char *lgh_name;
void *private_data;
struct llog_operations *lgh_logops;
- atomic_t lgh_refcount;
+ refcount_t lgh_refcount;
int lgh_max_size;
+ bool lgh_destroyed;
};
/* llog_osd.c */
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;
}
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,
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);
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);
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);
cgl->lgl_ogen, logid->lgl_ogen);
continue;
}
+ *res = llog_handle_get(loghandle);
+ if (!*res) {
+ CERROR("%s: log "DFID" refcount is zero!\n",
+ loghandle->lgh_ctxt->loc_obd->obd_name,
+ PFID(&logid->lgl_oi.oi_fid));
+ continue;
+ }
loghandle->u.phd.phd_cat_handle = cathandle;
up_write(&cathandle->lgh_lock);
- GOTO(out, rc = 0);
+ RETURN(rc);
}
}
up_write(&cathandle->lgh_lock);
rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN | fmt, NULL);
if (rc < 0) {
llog_close(env, loghandle);
- loghandle = NULL;
+ *res = NULL;
RETURN(rc);
}
+ *res = llog_handle_get(loghandle);
+ LASSERT(*res);
down_write(&cathandle->lgh_lock);
list_add_tail(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head);
up_write(&cathandle->lgh_lock);
loghandle->u.phd.phd_cookie.lgc_lgl = cathandle->lgh_id;
loghandle->u.phd.phd_cookie.lgc_index =
loghandle->lgh_hdr->llh_cat_idx;
- EXIT;
-out:
- llog_handle_get(loghandle);
- *res = loghandle;
- return 0;
+ RETURN(0);
}
int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle)
cathandle->lgh_ctxt->loc_obd->obd_name,
PFID(&lgl->lgl_oi.oi_fid), lgl->lgl_ogen, rc);
- llog_handle_put(loghandle);
+ llog_handle_put(env, loghandle);
RETURN(rc);
}
rc = 0;
}
- llog_handle_put(loghandle);
+ llog_handle_put(env, loghandle);
if (rc)
CERROR("%s: fail to cancel %d llog-records: rc = %d\n",
}
if (llh)
- llog_handle_put(llh);
+ llog_handle_put(env, llh);
RETURN(rc);
}
}
if (llh != NULL)
- llog_handle_put(llh);
+ llog_handle_put(env, llh);
RETURN(0);
}
rc = llog_cat_cleanup(env, cat_llh, llh,
llh->u.phd.phd_cookie.lgc_index);
- llog_handle_put(llh);
+ llog_handle_put(env, llh);
RETURN(rc);
}
int llog_info_init(void);
void llog_info_fini(void);
-void llog_handle_get(struct llog_handle *loghandle);
-void llog_handle_put(struct llog_handle *loghandle);
+struct llog_handle *llog_handle_get(struct llog_handle *loghandle);
+int llog_handle_put(const struct lu_env *env, struct llog_handle *loghandle);
int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
struct llog_handle **res, struct llog_logid *logid);
int class_config_dump_handler(const struct lu_env *env,
RETURN(rc);
}
rc = llog_process(env, loghandle, llog_check_cb, NULL, NULL);
- llog_handle_put(loghandle);
+ llog_handle_put(env, loghandle);
} else {
bool ok;
}
llog_cat_cleanup(env, cat, log, log->u.phd.phd_cookie.lgc_index);
out:
- llog_handle_put(log);
+ llog_handle_put(env, log);
RETURN(rc);
}
static int llog_osd_exist(struct llog_handle *handle)
{
LASSERT(handle->lgh_obj);
- return dt_object_exists(handle->lgh_obj) &&
- !lu_object_is_dying(handle->lgh_obj->do_lu.lo_header);
+ return dt_object_exists(handle->lgh_obj) && !handle->lgh_destroyed;
}
static void *rec_tail(struct llog_rec_hdr *rec)
o = loghandle->lgh_obj;
LASSERT(o);
- LASSERT(dt_object_exists(o));
+ LASSERT(llog_osd_exist(loghandle));
dt = lu2dt_dev(o->do_lu.lo_dev);
LASSERT(dt);
o = loghandle->lgh_obj;
LASSERT(o);
- LASSERT(dt_object_exists(o));
+ LASSERT(llog_osd_exist(loghandle));
dt = lu2dt_dev(o->do_lu.lo_dev);
LASSERT(dt);
LASSERT(o != NULL);
dt_write_lock(env, o, 0);
- if (!dt_object_exists(o))
+ if (!llog_osd_exist(loghandle))
GOTO(out_unlock, rc = 0);
if (loghandle->lgh_name) {
if (rc < 0)
GOTO(out_unlock, rc);
+ loghandle->lgh_destroyed = true;
if (loghandle->lgh_ctxt->loc_flags & LLOG_CTXT_FLAG_NORMAL_FID) {
rc = llog_osd_regular_fid_del_name_entry(env, o, th, false);
if (rc < 0)