From 2bbbcca375461d6a177035fa9fb7c4cae0b916cc Mon Sep 17 00:00:00 2001 From: tappro Date: Mon, 4 Sep 2006 06:58:06 +0000 Subject: [PATCH] - fix locking during mdd_open() - make mdd_get_md_locked() to avoid conditional locking in mdd_get_md() --- lustre/mdd/mdd_handler.c | 20 +++++++++++--------- lustre/mdd/mdd_internal.h | 4 +++- lustre/mdd/mdd_lov.c | 23 ++++++++++++++--------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/lustre/mdd/mdd_handler.c b/lustre/mdd/mdd_handler.c index d0aef07..00098c7 100644 --- a/lustre/mdd/mdd_handler.c +++ b/lustre/mdd/mdd_handler.c @@ -271,7 +271,7 @@ static int __mdd_lmm_get(const struct lu_context *ctxt, int rc; LASSERT(ma->ma_lmm != NULL && ma->ma_lmm_size > 0); - rc = mdd_get_md(ctxt, mdd_obj, ma->ma_lmm, &ma->ma_lmm_size, 0, + rc = mdd_get_md(ctxt, mdd_obj, ma->ma_lmm, &ma->ma_lmm_size, MDS_LOV_MD_NAME); if (rc > 0) { ma->ma_valid |= MA_LOV; @@ -287,7 +287,7 @@ static int __mdd_lmv_get(const struct lu_context *ctxt, { int rc; - rc = mdd_get_md(ctxt, mdd_obj, ma->ma_lmv, &ma->ma_lmv_size, 0, + rc = mdd_get_md(ctxt, mdd_obj, ma->ma_lmv, &ma->ma_lmv_size, MDS_LMV_MD_NAME); if (rc > 0) { ma->ma_valid |= MA_LMV; @@ -835,7 +835,7 @@ static int mdd_attr_set(const struct lu_context *ctxt, if (lmm == NULL) GOTO(cleanup, rc = -ENOMEM); - rc = mdd_get_md(ctxt, mdd_obj, lmm, &lmm_size, 1, + rc = mdd_get_md_locked(ctxt, mdd_obj, lmm, &lmm_size, MDS_LOV_MD_NAME); if (rc < 0) @@ -2033,18 +2033,20 @@ static int mdd_open(const struct lu_context *ctxt, struct md_object *obj, int flags) { int mode = accmode(md2mdd_obj(obj), flags); - - mdd_write_lock(ctxt, md2mdd_obj(obj)); + int rc = 0; + + mdd_read_lock(ctxt, md2mdd_obj(obj)); if (mode & MAY_WRITE) { if (mdd_is_immutable(md2mdd_obj(obj))) - RETURN(-EACCES); + rc = -EACCES; } - md2mdd_obj(obj)->mod_count ++; + if (rc == 0) + md2mdd_obj(obj)->mod_count ++; - mdd_write_unlock(ctxt, md2mdd_obj(obj)); - return 0; + mdd_read_unlock(ctxt, md2mdd_obj(obj)); + return rc; } static int mdd_close(const struct lu_context *ctxt, struct md_object *obj, diff --git a/lustre/mdd/mdd_internal.h b/lustre/mdd/mdd_internal.h index 6f0e552..b45a933 100644 --- a/lustre/mdd/mdd_internal.h +++ b/lustre/mdd/mdd_internal.h @@ -93,7 +93,9 @@ int mdd_lov_create(const struct lu_context *ctxt, struct mdd_device *mdd, const struct md_create_spec *spec, struct lu_attr *la); int mdd_get_md(const struct lu_context *ctxt, struct mdd_object *obj, - void *md, int *md_size, int need_locked, const char *name); + void *md, int *md_size, const char *name); +int mdd_get_md_locked(const struct lu_context *ctxt, struct mdd_object *obj, + void *md, int *md_size, const char *name); int mdd_unlink_log(const struct lu_context *ctxt, struct mdd_device *mdd, struct mdd_object *mdd_cobj, struct md_attr *ma); diff --git a/lustre/mdd/mdd_lov.c b/lustre/mdd/mdd_lov.c index bb310d5..846f669 100644 --- a/lustre/mdd/mdd_lov.c +++ b/lustre/mdd/mdd_lov.c @@ -178,14 +178,12 @@ lcfg_cleanup: } int mdd_get_md(const struct lu_context *ctxt, struct mdd_object *obj, - void *md, int *md_size, int need_locked, const char *name) + void *md, int *md_size, const char *name) { struct dt_object *next; int rc = 0; ENTRY; - if (need_locked) - mdd_read_lock(ctxt, obj); next = mdd_object_child(obj); rc = next->do_ops->do_xattr_get(ctxt, next, md, *md_size, name); /* @@ -202,12 +200,19 @@ int mdd_get_md(const struct lu_context *ctxt, struct mdd_object *obj, *md_size = rc; } - if (need_locked) - mdd_read_unlock(ctxt, obj); - RETURN (rc); } +int mdd_get_md_locked(const struct lu_context *ctxt, struct mdd_object *obj, + void *md, int *md_size, const char *name) +{ + int rc = 0; + mdd_read_lock(ctxt, obj); + rc = mdd_get_md(ctxt, obj, md, md_size, name); + mdd_read_unlock(ctxt, obj); + return rc; +} + static int mdd_lov_set_stripe_md(const struct lu_context *ctxt, struct mdd_object *obj, struct lov_mds_md *lmmp, int lmm_size, struct thandle *handle) @@ -284,7 +289,7 @@ int mdd_lov_set_md(const struct lu_context *ctxt, struct mdd_object *pobj, struct lov_mds_md *lmm = &mdd_ctx_info(ctxt)->mti_lmm; int size = sizeof(lmm); /*Get parent dir stripe and set*/ - rc = mdd_get_md(ctxt, pobj, &lmm, &size, 0, + rc = mdd_get_md(ctxt, pobj, &lmm, &size, MDS_LOV_MD_NAME); if (rc > 0) { rc = mdd_xattr_set_txn(ctxt, child, lmm, size, @@ -366,8 +371,8 @@ int mdd_lov_create(const struct lu_context *ctxt, struct mdd_device *mdd, if (__lmm == NULL) GOTO(out_oa, rc = -ENOMEM); - rc = mdd_get_md(ctxt, parent, __lmm, - &returned_lmm_size, 1, MDS_LOV_MD_NAME); + rc = mdd_get_md_locked(ctxt, parent, __lmm, + &returned_lmm_size, MDS_LOV_MD_NAME); if (rc > 0) rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE, lov_exp, 0, &lsm, __lmm); -- 1.8.3.1