X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fobdclass%2Fllog.c;h=8a24d05dcfa3712d18b6d20359417f2d662218da;hp=28aa947651a9965f25de5d49fa45ae9ec9c4f0cb;hb=d6bd5e9cc49b3bb9901ada503107e8b0eca44f7e;hpb=7c99f67d9d39e8a037e830cf08a9df305e6d8da2 diff --git a/lustre/obdclass/llog.c b/lustre/obdclass/llog.c index 28aa947..8a24d05 100644 --- a/lustre/obdclass/llog.c +++ b/lustre/obdclass/llog.c @@ -66,7 +66,7 @@ static struct llog_handle *llog_alloc_handle(void) mutex_init(&loghandle->lgh_hdr_mutex); init_rwsem(&loghandle->lgh_last_sem); INIT_LIST_HEAD(&loghandle->u.phd.phd_entry); - atomic_set(&loghandle->lgh_refcount, 1); + refcount_set(&loghandle->lgh_refcount, 1); return loghandle; } @@ -91,16 +91,30 @@ out: OBD_FREE_PTR(loghandle); } -void llog_handle_get(struct llog_handle *loghandle) +struct llog_handle *llog_handle_get(struct llog_handle *loghandle) { - atomic_inc(&loghandle->lgh_refcount); + if (refcount_inc_not_zero(&loghandle->lgh_refcount)) + return loghandle; + return NULL; } -void llog_handle_put(struct llog_handle *loghandle) +int llog_handle_put(const struct lu_env *env, struct llog_handle *loghandle) { - LASSERT(atomic_read(&loghandle->lgh_refcount) > 0); - if (atomic_dec_and_test(&loghandle->lgh_refcount)) + int rc = 0; + + if (refcount_dec_and_test(&loghandle->lgh_refcount)) { + struct llog_operations *lop; + + rc = llog_handle2ops(loghandle, &lop); + if (!rc) { + if (lop->lop_close) + rc = lop->lop_close(env, loghandle); + else + rc = -EOPNOTSUPP; + } llog_free_handle(loghandle); + } + return rc; } static int llog_declare_destroy(const struct lu_env *env, @@ -137,7 +151,7 @@ int llog_trans_destroy(const struct lu_env *env, struct llog_handle *handle, RETURN(-EOPNOTSUPP); LASSERT(handle->lgh_obj != NULL); - if (!dt_object_exists(handle->lgh_obj)) + if (!llog_exist(handle)) RETURN(0); rc = lop->lop_destroy(env, handle, th); @@ -166,7 +180,7 @@ int llog_destroy(const struct lu_env *env, struct llog_handle *handle) RETURN(rc); } - if (!dt_object_exists(handle->lgh_obj)) + if (!llog_exist(handle)) RETURN(0); dt = lu2dt_dev(handle->lgh_obj->do_lu.lo_dev); @@ -1306,20 +1320,7 @@ EXPORT_SYMBOL(llog_open); int llog_close(const struct lu_env *env, struct llog_handle *loghandle) { - struct llog_operations *lop; - int rc; - - ENTRY; - - rc = llog_handle2ops(loghandle, &lop); - if (rc) - GOTO(out, rc); - if (lop->lop_close == NULL) - GOTO(out, rc = -EOPNOTSUPP); - rc = lop->lop_close(env, loghandle); -out: - llog_handle_put(loghandle); - RETURN(rc); + return llog_handle_put(env, loghandle); } EXPORT_SYMBOL(llog_close);