This patch changes struct job_stat to use
kref(refcount_t) instead of atomic_t
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I02bcf91d4c19915bc37601c90172b1de37b87811
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52799
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
struct job_stat {
struct hlist_node js_hash; /* hash struct for this jobid */
struct list_head js_list; /* on ojs_list, with ojs_lock */
struct job_stat {
struct hlist_node js_hash; /* hash struct for this jobid */
struct list_head js_list; /* on ojs_list, with ojs_lock */
- atomic_t js_refcount; /* num users of this struct */
+ struct kref js_refcount; /* num users of this struct */
char js_jobid[LUSTRE_JOBID_SIZE]; /* job name + NUL*/
ktime_t js_time_init; /* time of initial stat*/
ktime_t js_time_latest; /* time of most recent stat*/
char js_jobid[LUSTRE_JOBID_SIZE]; /* job name + NUL*/
ktime_t js_time_init; /* time of initial stat*/
ktime_t js_time_latest; /* time of most recent stat*/
static bool job_getref_try(struct job_stat *job)
{
static bool job_getref_try(struct job_stat *job)
{
- return atomic_inc_not_zero(&job->js_refcount);
+ return kref_get_unless_zero(&job->js_refcount);
}
static void job_stat_get(struct cfs_hash *hs, struct hlist_node *hnode)
{
struct job_stat *job;
job = hlist_entry(hnode, struct job_stat, js_hash);
}
static void job_stat_get(struct cfs_hash *hs, struct hlist_node *hnode)
{
struct job_stat *job;
job = hlist_entry(hnode, struct job_stat, js_hash);
- atomic_inc(&job->js_refcount);
+ kref_get(&job->js_refcount);
}
static void job_reclaim_rcu(struct rcu_head *head)
}
static void job_reclaim_rcu(struct rcu_head *head)
-static void job_free(struct job_stat *job)
+static void job_free(struct kref *kref)
- LASSERT(atomic_read(&job->js_refcount) == 0);
- LASSERT(job->js_jobstats != NULL);
+ struct job_stat *job = container_of(kref, struct job_stat,
+ js_refcount);
+ LASSERT(job->js_jobstats != NULL);
spin_lock(&job->js_jobstats->ojs_lock);
list_del_rcu(&job->js_list);
spin_unlock(&job->js_jobstats->ojs_lock);
spin_lock(&job->js_jobstats->ojs_lock);
list_del_rcu(&job->js_list);
spin_unlock(&job->js_jobstats->ojs_lock);
static void job_putref(struct job_stat *job)
{
static void job_putref(struct job_stat *job)
{
- LASSERT(atomic_read(&job->js_refcount) > 0);
- if (atomic_dec_and_test(&job->js_refcount))
- job_free(job);
+ LASSERT(kref_read(&job->js_refcount) > 0);
+ kref_put(&job->js_refcount, job_free);
}
static void job_stat_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
}
static void job_stat_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
job->js_jobstats = jobs;
INIT_HLIST_NODE(&job->js_hash);
INIT_LIST_HEAD(&job->js_list);
job->js_jobstats = jobs;
INIT_HLIST_NODE(&job->js_hash);
INIT_LIST_HEAD(&job->js_list);
- atomic_set(&job->js_refcount, 1);
+ kref_init(&job->js_refcount);