#define TOP_THANDLE_MAGIC 0x20140917
struct top_multiple_thandle {
struct dt_device *tmt_master_sub_dt;
- atomic_t tmt_refcount;
+ struct kref tmt_refcount;
/* Other sub transactions will be listed here. */
struct list_head tmt_sub_thandle_list;
spinlock_t tmt_sub_lock;
struct thandle *th);
int top_trans_stop(const struct lu_env *env, struct dt_device *master_dev,
struct thandle *th);
-void top_multiple_thandle_destroy(struct top_multiple_thandle *tmt);
+void top_multiple_thandle_destroy(struct kref *kref);
static inline void top_multiple_thandle_get(struct top_multiple_thandle *tmt)
{
- atomic_inc(&tmt->tmt_refcount);
+ kref_get(&tmt->tmt_refcount);
}
static inline void top_multiple_thandle_put(struct top_multiple_thandle *tmt)
{
- if (atomic_dec_and_test(&tmt->tmt_refcount))
- top_multiple_thandle_destroy(tmt);
+ kref_put(&tmt->tmt_refcount, top_multiple_thandle_destroy);
}
struct sub_thandle *lookup_sub_thandle(struct top_multiple_thandle *tmt,
tmt->tmt_master_sub_dt ?
tmt->tmt_master_sub_dt->dd_lu_dev.ld_obd->obd_name :
"NULL",
- tmt, atomic_read(&tmt->tmt_refcount), tmt->tmt_committed,
+ tmt, kref_read(&tmt->tmt_refcount), tmt->tmt_committed,
tmt->tmt_result, tmt->tmt_batchid);
list_for_each_entry(st, &tmt->tmt_sub_thandle_list, st_sub_list) {
struct lu_target *lut;
ENTRY;
- LASSERT(atomic_read(&tmt->tmt_refcount) > 0);
+ LASSERT(kref_read(&tmt->tmt_refcount) > 0);
top_multiple_thandle_dump(tmt, D_HA);
tmt->tmt_committed = 1;
tmt->tmt_magic = TOP_THANDLE_MAGIC;
INIT_LIST_HEAD(&tmt->tmt_sub_thandle_list);
INIT_LIST_HEAD(&tmt->tmt_commit_list);
- atomic_set(&tmt->tmt_refcount, 1);
+ kref_init(&tmt->tmt_refcount);
spin_lock_init(&tmt->tmt_sub_lock);
init_waitqueue_head(&tmt->tmt_stop_waitq);
*
* Destroy multiple thandle and all its sub thandle.
*
- * \param[in] tmt top_multiple_thandle to be destroyed.
+ * \param[in] kref Pointer to struct kref
*/
-void top_multiple_thandle_destroy(struct top_multiple_thandle *tmt)
+void top_multiple_thandle_destroy(struct kref *kref)
{
+ struct top_multiple_thandle *tmt;
struct sub_thandle *st;
struct sub_thandle *tmp;
+ tmt = container_of(kref, struct top_multiple_thandle, tmt_refcount);
+
LASSERT(tmt->tmt_magic == TOP_THANDLE_MAGIC);
list_for_each_entry_safe(st, tmp, &tmt->tmt_sub_thandle_list,
st_sub_list) {