From: wangdi Date: Thu, 26 Sep 2013 13:16:26 +0000 (-0700) Subject: LU-1506 ldlm: correct lock res build for FID on OST X-Git-Tag: 2.3.60~9 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=6127755112c62e707d4c42ada368c2cdde40149c LU-1506 ldlm: correct lock res build for FID on OST Because 1.8/2.1/2.2 client always put oid to res[0] and oseq to res[1], OFD will do the same to avoid incompatible problems. Signed-off-by: wang di Change-Id: Ic4cf66b1bc23631af42530787796510653f82a61 Reviewed-on: http://review.whamcloud.com/3081 Tested-by: Hudson Reviewed-by: Mike Pershin Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h index 50151d5..d5b6bce 100644 --- a/lustre/include/lustre/lustre_idl.h +++ b/lustre/include/lustre/lustre_idl.h @@ -1581,12 +1581,14 @@ extern void lustre_swab_obd_statfs (struct obd_statfs *os); #define OST_MAX_PRECREATE 20000 struct obd_ioobj { - obd_id ioo_id; - obd_seq ioo_seq; - __u32 ioo_type; - __u32 ioo_bufcnt; + struct ost_id ioo_oid; + __u32 ioo_type; + __u32 ioo_bufcnt; }; +#define ioo_id ioo_oid.oi_id +#define ioo_seq ioo_oid.oi_seq + extern void lustre_swab_obd_ioobj (struct obd_ioobj *ioo); /* multiple of 8 bytes => can array */ diff --git a/lustre/include/lustre_fid.h b/lustre/include/lustre_fid.h index 7721273..d469035 100644 --- a/lustre/include/lustre_fid.h +++ b/lustre/include/lustre_fid.h @@ -519,6 +519,36 @@ fid_build_pdo_res_name(const struct lu_fid *f, return name; } +/** + * Build DLM resource name from object id & seq, which will be removed + * finally, when we replace ost_id with FID in data stack. + * + * To keep the compatibility, res[0] = oid, res[1] = seq + */ +static inline void ostid_build_res_name(struct ost_id *oid, + struct ldlm_res_id *name) +{ + memset(name, 0, sizeof *name); + name->name[LUSTRE_RES_ID_SEQ_OFF] = oid->oi_id; + name->name[LUSTRE_RES_ID_VER_OID_OFF] = oid->oi_seq; +} + +static inline void ostid_res_name_to_id(struct ost_id *oid, + struct ldlm_res_id *name) +{ + oid->oi_id = name->name[LUSTRE_RES_ID_SEQ_OFF]; + oid->oi_seq = name->name[LUSTRE_RES_ID_VER_OID_OFF]; +} + +/** + * Return true if the resource is for the object identified by this id & group. + */ +static inline int ostid_res_name_eq(struct ost_id *oid, + struct ldlm_res_id *name) +{ + return name->name[LUSTRE_RES_ID_SEQ_OFF] == oid->oi_id && + name->name[LUSTRE_RES_ID_VER_OID_OFF] == oid->oi_seq; +} /** * Flatten 128-bit FID values into a 64-bit value for use as an inode number. diff --git a/lustre/include/obd.h b/lustre/include/obd.h index bfc40a8..3455924 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -110,8 +110,7 @@ struct lov_stripe_md { __u64 lsm_maxbytes; struct { /* Public members. */ - __u64 lw_object_id; /* lov object id */ - __u64 lw_object_seq; /* lov object seq */ + struct ost_id lw_object_oid; /* lov object id/seq */ /* LOV-private members start here -- only for use in lov/. */ __u32 lw_magic; @@ -125,8 +124,9 @@ struct lov_stripe_md { struct lov_oinfo *lsm_oinfo[0]; }; -#define lsm_object_id lsm_wire.lw_object_id -#define lsm_object_seq lsm_wire.lw_object_seq +#define lsm_object_oid lsm_wire.lw_object_oid +#define lsm_object_id lsm_wire.lw_object_oid.oi_id +#define lsm_object_seq lsm_wire.lw_object_oid.oi_seq #define lsm_magic lsm_wire.lw_magic #define lsm_layout_gen lsm_wire.lw_layout_gen #define lsm_stripe_size lsm_wire.lw_stripe_size diff --git a/lustre/include/obd_ost.h b/lustre/include/obd_ost.h index bdf35c2..feeb445 100644 --- a/lustre/include/obd_ost.h +++ b/lustre/include/obd_ost.h @@ -94,24 +94,5 @@ int osc_extent_blocking_cb(struct ldlm_lock *lock, #endif #define POSTID LPU64":"LPU64 -/** - * Build DLM resource name from object id & group for osc-ost extent lock. - */ -static inline struct ldlm_res_id *osc_build_res_name(__u64 id, __u64 gr, - struct ldlm_res_id *name) -{ - memset(name, 0, sizeof *name); - name->name[0] = id; - name->name[1] = gr; - return name; -} - -/** - * Return true if the resource is for the object identified by this id & group. - */ -static inline int osc_res_name_eq(__u64 id, __u64 gr, struct ldlm_res_id *name) -{ - return name->name[0] == id && name->name[1] == gr; -} #endif diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c index 3c5738a..74cabb9 100644 --- a/lustre/lov/lov_obd.c +++ b/lustre/lov/lov_obd.c @@ -64,6 +64,7 @@ #include /* for cl_client_lru */ #include #include +#include #include "lov_internal.h" @@ -2480,12 +2481,12 @@ static int lov_get_info(const struct lu_env *env, struct obd_export *exp, loi = lsm->lsm_oinfo[i]; if (!lov->lov_tgts[loi->loi_ost_idx]) continue; - if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp == - data->lock->l_conn_export && - osc_res_name_eq(loi->loi_id, loi->loi_seq, res_id)) { - *stripe = i; - GOTO(out, rc = 0); - } + if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp == + data->lock->l_conn_export && + ostid_res_name_eq(&loi->loi_oi, res_id)) { + *stripe = i; + GOTO(out, rc = 0); + } } LDLM_ERROR(data->lock, "lock on inode without such object"); dump_lsm(D_ERROR, lsm); diff --git a/lustre/ofd/ofd_internal.h b/lustre/ofd/ofd_internal.h index 63d324e..4756484 100644 --- a/lustre/ofd/ofd_internal.h +++ b/lustre/ofd/ofd_internal.h @@ -537,33 +537,28 @@ static inline struct ofd_thread_info * ofd_info_init(const struct lu_env *env, static inline void ofd_build_resid(const struct lu_fid *fid, struct ldlm_res_id *resname) { + struct ost_id oid; + if (fid_is_idif(fid)) { - /* get id/seq like ostid_idif_pack() does */ - osc_build_res_name(fid_idif_id(fid_seq(fid), fid_oid(fid), - fid_ver(fid)), - FID_SEQ_OST_MDT0, resname); + oid.oi_id = fid_idif_id(fid_seq(fid), fid_oid(fid), + fid_ver(fid)); + oid.oi_seq = FID_SEQ_OST_MDT0; } else { - /* In the future, where OSTs have FID sequences allocated. */ - fid_build_reg_res_name(fid, resname); + oid.oi_id = fid_oid(fid); + oid.oi_seq = fid_seq(fid); } + ostid_build_res_name(&oid, resname); } static inline void ofd_fid_from_resid(struct lu_fid *fid, const struct ldlm_res_id *name) { - /* if seq is FID_SEQ_OST_MDT0 then we have IDIF and resid was built - * using osc_build_res_name function. */ - if (fid_seq_is_mdt0(name->name[LUSTRE_RES_ID_VER_OID_OFF])) { - struct ost_id ostid; - - ostid.oi_id = name->name[LUSTRE_RES_ID_SEQ_OFF]; - ostid.oi_seq = name->name[LUSTRE_RES_ID_VER_OID_OFF]; - fid_ostid_unpack(fid, &ostid, 0); - } else { - fid->f_seq = name->name[LUSTRE_RES_ID_SEQ_OFF]; - fid->f_oid = (__u32)name->name[LUSTRE_RES_ID_VER_OID_OFF]; - fid->f_ver = name->name[LUSTRE_RES_ID_VER_OID_OFF] >> 32; - } + /* To keep compatiblity, res[0] = oi_id, res[1] = oi_seq. */ + struct ost_id ostid; + + ostid.oi_id = name->name[LUSTRE_RES_ID_SEQ_OFF]; + ostid.oi_seq = name->name[LUSTRE_RES_ID_VER_OID_OFF]; + fid_ostid_unpack(fid, &ostid, 0); } static inline void ofd_oti2info(struct ofd_thread_info *info, diff --git a/lustre/osc/osc_cl_internal.h b/lustre/osc/osc_cl_internal.h index de2b2df..2777010 100644 --- a/lustre/osc/osc_cl_internal.h +++ b/lustre/osc/osc_cl_internal.h @@ -429,8 +429,6 @@ struct lu_object *osc_object_alloc(const struct lu_env *env, int osc_page_init(const struct lu_env *env, struct cl_object *obj, struct cl_page *page, cfs_page_t *vmpage); -void osc_lock_build_res(const struct lu_env *env, const struct osc_object *obj, - struct ldlm_res_id *resname); void osc_index2policy (ldlm_policy_data_t *policy, const struct cl_object *obj, pgoff_t start, pgoff_t end); int osc_lvb_print (const struct lu_env *env, void *cookie, diff --git a/lustre/osc/osc_lock.c b/lustre/osc/osc_lock.c index 21c2ff09..b09cb0b 100644 --- a/lustre/osc/osc_lock.c +++ b/lustre/osc/osc_lock.c @@ -244,26 +244,6 @@ static void osc_lock_fini(const struct lu_env *env, OBD_SLAB_FREE_PTR(ols, osc_lock_kmem); } -void osc_lock_build_res(const struct lu_env *env, const struct osc_object *obj, - struct ldlm_res_id *resname) -{ - const struct lu_fid *fid = lu_object_fid(&obj->oo_cl.co_lu); - if (0) { - /* - * In the perfect world of the future, where ost servers talk - * idif-fids... - */ - fid_build_reg_res_name(fid, resname); - } else { - /* - * In reality, where ost server expects ->lsm_object_id and - * ->lsm_object_seq in rename. - */ - osc_build_res_name(obj->oo_oinfo->loi_id, obj->oo_oinfo->loi_seq, - resname); - } -} - static void osc_lock_build_policy(const struct lu_env *env, const struct cl_lock *lock, ldlm_policy_data_t *policy) @@ -1208,7 +1188,7 @@ static int osc_lock_enqueue(const struct lu_env *env, * ldlm_lock_match(LDLM_FL_LVB_READY) waits for * LDLM_CP_CALLBACK. */ - osc_lock_build_res(env, obj, resname); + ostid_build_res_name(&obj->oo_oinfo->loi_oi, resname); osc_lock_build_policy(env, lock, policy); result = osc_enqueue_base(osc_export(obj), resname, &ols->ols_flags, policy, diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index 64c288d..c6cd621 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -58,6 +58,7 @@ #include #include #include +#include #include "osc_internal.h" #include "osc_cl_internal.h" @@ -671,10 +672,10 @@ static int osc_resource_get_unused(struct obd_export *exp, struct obdo *oa, if (exp_connect_cancelset(exp) && !ns_connect_cancelset(ns)) RETURN(0); - osc_build_res_name(oa->o_id, oa->o_seq, &res_id); - res = ldlm_resource_get(ns, NULL, &res_id, 0, 0); - if (res == NULL) - RETURN(0); + ostid_build_res_name(&oa->o_oi, &res_id); + res = ldlm_resource_get(ns, NULL, &res_id, 0, 0); + if (res == NULL) + RETURN(0); LDLM_RESOURCE_ADDREF(res); count = ldlm_cancel_resource_local(res, cancels, NULL, mode, @@ -2295,7 +2296,7 @@ static int osc_change_cbdata(struct obd_export *exp, struct lov_stripe_md *lsm, struct ldlm_res_id res_id; struct obd_device *obd = class_exp2obd(exp); - osc_build_res_name(lsm->lsm_object_id, lsm->lsm_object_seq, &res_id); + ostid_build_res_name(&lsm->lsm_object_oid, &res_id); ldlm_resource_iterate(obd->obd_namespace, &res_id, replace, data); return 0; } @@ -2311,7 +2312,7 @@ static int osc_find_cbdata(struct obd_export *exp, struct lov_stripe_md *lsm, struct obd_device *obd = class_exp2obd(exp); int rc = 0; - osc_build_res_name(lsm->lsm_object_id, lsm->lsm_object_seq, &res_id); + ostid_build_res_name(&lsm->lsm_object_oid, &res_id); rc = ldlm_resource_iterate(obd->obd_namespace, &res_id, replace, data); if (rc == LDLM_ITER_STOP) return(1); @@ -2621,9 +2622,7 @@ static int osc_enqueue(struct obd_export *exp, struct obd_info *oinfo, int rc; ENTRY; - osc_build_res_name(oinfo->oi_md->lsm_object_id, - oinfo->oi_md->lsm_object_seq, &res_id); - + ostid_build_res_name(&oinfo->oi_md->lsm_object_oid, &res_id); rc = osc_enqueue_base(exp, &res_id, &oinfo->oi_flags, &oinfo->oi_policy, &oinfo->oi_md->lsm_oinfo[0]->loi_lvb, oinfo->oi_md->lsm_oinfo[0]->loi_kms_valid, @@ -2703,10 +2702,10 @@ static int osc_cancel_unused(struct obd_export *exp, struct obd_device *obd = class_exp2obd(exp); struct ldlm_res_id res_id, *resp = NULL; - if (lsm != NULL) { - resp = osc_build_res_name(lsm->lsm_object_id, - lsm->lsm_object_seq, &res_id); - } + if (lsm != NULL) { + ostid_build_res_name(&lsm->lsm_object_oid, &res_id); + resp = &res_id; + } return ldlm_cli_cancel_unused(obd->obd_namespace, resp, flags, opaque); } diff --git a/lustre/ost/ost_handler.c b/lustre/ost/ost_handler.c index 81be2f1..6dfc652 100644 --- a/lustre/ost/ost_handler.c +++ b/lustre/ost/ost_handler.c @@ -53,6 +53,8 @@ #include #include #include +#include +#include #include "ost_internal.h" #include @@ -234,7 +236,7 @@ static int ost_lock_get(struct obd_export *exp, struct obdo *oa, !(oa->o_flags & OBD_FL_SRVLOCK)) RETURN(0); - osc_build_res_name(oa->o_id, oa->o_seq, &res_id); + ostid_build_res_name(&oa->o_oi, &res_id); CDEBUG(D_INODE, "OST-side extent lock.\n"); policy.l_extent.start = start & CFS_PAGE_MASK; @@ -628,7 +630,7 @@ static int ost_brw_lock_get(int mode, struct obd_export *exp, int i; ENTRY; - osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id); + ostid_build_res_name(&obj->ioo_oid, &res_id); LASSERT(mode == LCK_PR || mode == LCK_PW); LASSERT(!lustre_handle_is_used(lh)); @@ -1616,8 +1618,8 @@ int ost_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc, OBD_FREE_PTR(oinfo); GOTO(out_env, rc = -ENOMEM); } - oa->o_id = lock->l_resource->lr_name.name[0]; - oa->o_seq = lock->l_resource->lr_name.name[1]; + + ostid_res_name_to_id(&oa->o_oi, &lock->l_resource->lr_name); oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP; oinfo->oi_oa = oa; oinfo->oi_capa = BYPASS_CAPA; @@ -1869,10 +1871,9 @@ static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req, nb += ioo->ioo_bufcnt - 1; ext.end = nb->offset + nb->len - 1; - LASSERT(lock->l_resource != NULL); - if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq, - &lock->l_resource->lr_name)) - RETURN(0); + LASSERT(lock->l_resource != NULL); + if (!ostid_res_name_eq(&ioo->ioo_oid, &lock->l_resource->lr_name)) + RETURN(0); mode = LCK_PW; if (opc == OST_READ) @@ -1920,7 +1921,7 @@ static int ost_rw_hpreq_check(struct ptlrpc_request *req) LASSERT(nb != NULL); LASSERT(!(nb->flags & OBD_BRW_SRVLOCK)); - osc_build_res_name(ioo->ioo_id, ioo->ioo_seq, &opd.opd_resid); + ostid_build_res_name(&ioo->ioo_oid, &opd.opd_resid); opd.opd_req = req; mode = LCK_PW; @@ -2004,7 +2005,7 @@ static int ost_punch_hpreq_check(struct ptlrpc_request *req) opd.opd_extent.end = OBD_OBJECT_EOF; opd.opd_timeout = prolong_timeout(req); - osc_build_res_name(oa->o_id, oa->o_seq, &opd.opd_resid); + ostid_build_res_name(&oa->o_oi, &opd.opd_resid); CDEBUG(D_DLMTRACE, "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",