From: yury Date: Fri, 20 Oct 2006 11:27:36 +0000 (+0000) Subject: - convert mdl locks to ldlm ones in more samtr way; X-Git-Tag: v1_8_0_110~486^2~416 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=cfa555179acc95e39e5afc322f18dbdde3d497af;p=fs%2Flustre-release.git - convert mdl locks to ldlm ones in more samtr way; - add client part of pdirops locks. --- diff --git a/lustre/cmm/cmm_object.c b/lustre/cmm/cmm_object.c index a2086d3..d2c9a2e 100644 --- a/lustre/cmm/cmm_object.c +++ b/lustre/cmm/cmm_object.c @@ -372,8 +372,8 @@ static int cml_lookup(const struct lu_env *env, struct md_object *mo_p, } -static lu_mode_t cml_lock_mode(const struct lu_env *env, - struct md_object *mo, lu_mode_t lm) +static mdl_mode_t cml_lock_mode(const struct lu_env *env, + struct md_object *mo, mdl_mode_t lm) { ENTRY; #ifdef HAVE_SPLIT_SUPPORT @@ -381,15 +381,15 @@ static lu_mode_t cml_lock_mode(const struct lu_env *env, struct md_attr *ma = &cmm_env_info(env)->cmi_ma; /* - * Check only if need protection from split. If not mdt handles - * other cases. + * Check only if we need protection from split. If not - mdt + * handles other cases. */ - if (lm == LU_PW && + if (lm == MDL_PW && cmm_expect_splitting(env, mo, ma) == CMM_EXPECT_SPLIT) - RETURN(LU_EX); + RETURN(MDL_EX); } #endif - RETURN(LU_MINMODE); + RETURN(MDL_MINMODE); } static int cml_create(const struct lu_env *env, @@ -779,10 +779,10 @@ static int cmr_lookup(const struct lu_env *env, struct md_object *mo_p, RETURN(-EREMOTE); } -static lu_mode_t cmr_lock_mode(const struct lu_env *env, - struct md_object *mo, lu_mode_t lm) +static mdl_mode_t cmr_lock_mode(const struct lu_env *env, + struct md_object *mo, mdl_mode_t lm) { - RETURN(LU_MINMODE); + RETURN(MDL_MINMODE); } /* diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h index 8616386..ddcbd80 100644 --- a/lustre/include/lustre/lustre_idl.h +++ b/lustre/include/lustre/lustre_idl.h @@ -1454,18 +1454,6 @@ typedef enum { } ldlm_mode_t; typedef enum { - LU_MINMODE = 0, - LU_EX = 1, - LU_PW = 2, - LU_PR = 4, - LU_CW = 8, - LU_CR = 16, - LU_NL = 32, - LU_GROUP = 64, - LU_MAXMODE -} lu_mode_t; - -typedef enum { LDLM_PLAIN = 10, LDLM_EXTENT = 11, LDLM_FLOCK = 12, diff --git a/lustre/include/md_object.h b/lustre/include/md_object.h index e864249..d907a9b 100644 --- a/lustre/include/md_object.h +++ b/lustre/include/md_object.h @@ -93,14 +93,26 @@ struct md_capainfo *md_capainfo(const struct lu_env *env); /* metadata attributes */ enum ma_valid { - MA_INODE = (1 << 0), - MA_LOV = (1 << 1), - MA_COOKIE = (1 << 2), - MA_FLAGS = (1 << 3), - MA_LMV = (1 << 4), - MA_ACL_DEF = (1 << 5) + MA_INODE = (1 << 0), + MA_LOV = (1 << 1), + MA_COOKIE = (1 << 2), + MA_FLAGS = (1 << 3), + MA_LMV = (1 << 4), + MA_ACL_DEF = (1 << 5) }; +typedef enum { + MDL_MINMODE = 0, + MDL_EX = 1, + MDL_PW = 2, + MDL_PR = 4, + MDL_CW = 8, + MDL_CR = 16, + MDL_NL = 32, + MDL_GROUP = 64, + MDL_MAXMODE +} mdl_mode_t; + struct md_attr { __u64 ma_valid; __u64 ma_need; @@ -198,8 +210,8 @@ struct md_dir_operations { int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj, const char *name, struct lu_fid *fid); - lu_mode_t (*mdo_lock_mode)(const struct lu_env *env, struct md_object *obj, - lu_mode_t mode); + mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env, struct md_object *obj, + mdl_mode_t mode); int (*mdo_create)(const struct lu_env *env, struct md_object *pobj, const char *name, struct md_object *child, @@ -459,12 +471,12 @@ static inline int mdo_lookup(const struct lu_env *env, return p->mo_dir_ops->mdo_lookup(env, p, name, f); } -static inline lu_mode_t mdo_lock_mode(const struct lu_env *env, - struct md_object *mo, - lu_mode_t lm) +static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env, + struct md_object *mo, + mdl_mode_t lm) { if (mo->mo_dir_ops->mdo_lock_mode == NULL) - return LU_MINMODE; + return MDL_MINMODE; return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm); } diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 6a64959..7a99bac 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -278,14 +278,20 @@ static struct page *ll_get_dir_page(struct inode *dir, __u32 hash, int exact, ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} }; struct address_space *mapping = dir->i_mapping; struct lustre_handle lockh; - struct page *page; struct lu_dirpage *dp; + struct page *page; + ldlm_mode_t mode; int rc; __u32 start; __u32 end; +#ifdef CONFIG_PDIROPS + mode = LCK_PR; +#else + mode = LCK_CR; +#endif rc = md_lock_match(ll_i2sbi(dir)->ll_md_exp, LDLM_FL_BLOCK_GRANTED, - ll_inode2fid(dir), LDLM_IBITS, &policy, LCK_CR, &lockh); + ll_inode2fid(dir), LDLM_IBITS, &policy, mode, &lockh); if (!rc) { struct lookup_intent it = { .it_op = IT_READDIR }; struct ptlrpc_request *request; @@ -296,7 +302,7 @@ static struct page *ll_get_dir_page(struct inode *dir, __u32 hash, int exact, return ERR_PTR(-ENOMEM); rc = md_enqueue(ll_i2sbi(dir)->ll_md_exp, LDLM_IBITS, &it, - LCK_CR, op_data, &lockh, NULL, 0, + mode, op_data, &lockh, NULL, 0, ldlm_completion_ast, ll_md_blocking_ast, dir, 0); @@ -381,7 +387,7 @@ hash_collision: goto fail; } out_unlock: - ldlm_lock_decref(&lockh, LCK_CR); + ldlm_lock_decref(&lockh, mode); return page; fail: diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 4821b0e..89a9554 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -342,7 +342,7 @@ static int ll_intent_file_open(struct file *file, void *lmm, if (op_data == NULL) RETURN(-ENOMEM); - rc = md_enqueue(sbi->ll_md_exp, LDLM_IBITS, itp, LCK_PW, op_data, + rc = md_enqueue(sbi->ll_md_exp, LDLM_IBITS, itp, LCK_CW, op_data, &lockh, lmm, lmmsize, ldlm_completion_ast, ll_md_blocking_ast, NULL, 0); @@ -372,7 +372,7 @@ static int ll_och_fill(struct obd_export *md_exp, struct ll_inode_info *lli, LASSERT(och); body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body)); - LASSERT(body != NULL); /* reply already checked out */ + LASSERT(body != NULL); /* reply already checked out */ LASSERT_REPSWABBED(req, DLM_REPLY_REC_OFF); /* and swabbed in md_enqueue */ memcpy(&och->och_fh, &body->handle, sizeof(body->handle)); @@ -1890,7 +1890,7 @@ static int join_file(struct inode *head_inode, struct file *head_filp, if (op_data == NULL) RETURN(-ENOMEM); - rc = md_enqueue(ll_i2mdexp(head_inode), LDLM_IBITS, &oit, LCK_PW, + rc = md_enqueue(ll_i2mdexp(head_inode), LDLM_IBITS, &oit, LCK_CW, op_data, &lockh, &tsize, 0, ldlm_completion_ast, ll_md_blocking_ast, &hsize, 0); diff --git a/lustre/mdc/mdc_locks.c b/lustre/mdc/mdc_locks.c index aaadeee..08e92c5 100644 --- a/lustre/mdc/mdc_locks.c +++ b/lustre/mdc/mdc_locks.c @@ -62,11 +62,21 @@ EXPORT_SYMBOL(it_clear_disposition); static int it_to_lock_mode(struct lookup_intent *it) { + ENTRY; + +#ifdef CONFIG_PDIROPS + /* CREAT needs to be tested before open (both could be set) */ + if (it->it_op & IT_CREAT) + return LCK_PW; + else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP)) + return LCK_PR; +#else /* CREAT needs to be tested before open (both could be set) */ if (it->it_op & IT_CREAT) return LCK_CW; else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP)) return LCK_CR; +#endif LBUG(); RETURN(-EINVAL); @@ -653,7 +663,7 @@ int mdc_intent_lock(struct obd_export *exp, struct md_op_data *op_data, fid_ver(&op_data->fid2) } }; struct lustre_handle lockh; ldlm_policy_data_t policy; - int mode = LCK_CR; + ldlm_mode_t mode = LCK_CR; /* As not all attributes are kept under update lock, e.g. owner/group/acls are under lookup lock, we need both @@ -668,19 +678,20 @@ int mdc_intent_lock(struct obd_export *exp, struct md_op_data *op_data, rc = ldlm_lock_match(exp->exp_obd->obd_namespace, LDLM_FL_BLOCK_GRANTED, &res_id, - LDLM_IBITS, &policy, LCK_CR, &lockh); + LDLM_IBITS, &policy, mode, &lockh); if (!rc) { mode = LCK_CW; rc = ldlm_lock_match(exp->exp_obd->obd_namespace, LDLM_FL_BLOCK_GRANTED, &res_id, - LDLM_IBITS, &policy, LCK_CW, &lockh); + LDLM_IBITS, &policy, mode, &lockh); } if (!rc) { mode = LCK_PR; rc = ldlm_lock_match(exp->exp_obd->obd_namespace, LDLM_FL_BLOCK_GRANTED, &res_id, - LDLM_IBITS, &policy, LCK_PR, &lockh); + LDLM_IBITS, &policy, mode, &lockh); } + if (rc) { memcpy(&it->d.lustre.it_lock_handle, &lockh, sizeof(lockh)); diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 585dc83..b7cc683 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -1411,10 +1411,48 @@ struct mdt_object *mdt_object_find(const struct lu_env *env, RETURN(m); } -int mdt_object_lock_mode(struct mdt_thread_info *info, - struct mdt_object *o, - struct mdt_lock_handle *lh, - ldlm_mode_t lm) +static mdl_mode_t mdt_mdl_lock_modes[] = { + [0] = MDL_MINMODE, + [1] = MDL_EX, + [2] = MDL_PW, + [3] = MDL_PR, + [4] = MDL_CW, + [5] = MDL_CR, + [6] = MDL_NL, + [7] = MDL_GROUP +}; + +static ldlm_mode_t mdt_ldlm_lock_modes[] = { + [0] = LCK_MINMODE, + [1] = LCK_EX, + [2] = LCK_PW, + [3] = LCK_PR, + [4] = LCK_CW, + [5] = LCK_CR, + [6] = LCK_NL, + [7] = LCK_GROUP +}; + +static inline mdl_mode_t mdt_ldlm_mode2mdl_mode(ldlm_mode_t mode) +{ + int idx = ffs((int)mode) - 1; + LASSERT(idx >= 0); + LASSERT(IS_PO2(mode)); + LASSERT(idx < ARRAY_SIZE(mdt_mdl_lock_modes)); + return mdt_mdl_lock_modes[idx]; +} + +static inline ldlm_mode_t mdt_mdl_mode2ldlm_mode(mdl_mode_t mode) +{ + int idx = ffs((int)mode) - 1; + LASSERT(idx >= 0); + LASSERT(IS_PO2(mode)); + LASSERT(idx < ARRAY_SIZE(mdt_ldlm_lock_modes)); + return mdt_ldlm_lock_modes[idx]; +} + +int mdt_lock_init_mode(struct mdt_thread_info *info, struct mdt_object *o, + struct mdt_lock_handle *lh, ldlm_mode_t lm) { ENTRY; @@ -1422,7 +1460,7 @@ int mdt_object_lock_mode(struct mdt_thread_info *info, #ifdef CONFIG_PDIROPS { - lu_mode_t mode; + mdl_mode_t mode; /* * Any dir access needs couple of locks: @@ -1448,10 +1486,10 @@ int mdt_object_lock_mode(struct mdt_thread_info *info, /* Ask underlaying level its opinion about possible locks. */ mode = mdo_lock_mode(info->mti_env, mdt_object_child(o), - mdt_ldlm_mode2lu_mode(lm)); - if (mode != LU_MINMODE) { + mdt_ldlm_mode2mdl_mode(lm)); + if (mode != MDL_MINMODE) { /* Lower layer said what lock mode it likes to be, use it. */ - lh->mlh_pdo_mode = mdt_lu_mode2ldlm_mode(mode); + lh->mlh_pdo_mode = mdt_mdl_mode2ldlm_mode(mode); } else { /* * Lower layer does not want to specify locking mode. We od it diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 559fa35..3250a7c 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -632,54 +632,6 @@ static inline int is_identity_get_disabled(struct upcall_cache *cache) return cache ? (strcmp(cache->uc_upcall, "NONE") == 0) : 1; } -static inline lu_mode_t mdt_ldlm_mode2lu_mode(ldlm_mode_t mode) -{ - switch (mode) { - case LCK_MINMODE: - return LU_MINMODE; - case LCK_EX: - return LU_EX; - case LCK_PW: - return LU_PW; - case LCK_PR: - return LU_PR; - case LCK_CW: - return LU_CW; - case LCK_CR: - return LU_CR; - case LCK_NL: - return LU_NL; - case LCK_GROUP: - return LU_GROUP; - default: - return 0; - } -} - -static inline ldlm_mode_t mdt_lu_mode2ldlm_mode(lu_mode_t mode) -{ - switch (mode) { - case LU_MINMODE: - return LCK_MINMODE; - case LU_EX: - return LCK_EX; - case LU_PW: - return LCK_PW; - case LU_PR: - return LCK_PR; - case LU_CW: - return LCK_CW; - case LU_CR: - return LCK_CR; - case LU_NL: - return LCK_NL; - case LU_GROUP: - return LCK_GROUP; - default: - return 0; - } -} - /* * Capability */