X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fobdclass%2Flprocfs_jobstats.c;h=a06491645e3636508a65b036879c256c7009f262;hb=refs%2Fchanges%2F74%2F13174%2F2;hp=e6eb7384e175ef46a50e478896f1f2e04e38678b;hpb=98060d83459ba10409f295898f0ec917f938b4d3;p=fs%2Flustre-release.git diff --git a/lustre/obdclass/lprocfs_jobstats.c b/lustre/obdclass/lprocfs_jobstats.c index e6eb738..a064916 100644 --- a/lustre/obdclass/lprocfs_jobstats.c +++ b/lustre/obdclass/lprocfs_jobstats.c @@ -19,7 +19,7 @@ * GPL HEADER END */ /* - * Copyright (c) 2012, 2013, Intel Corporation. + * Copyright (c) 2012, 2014, Intel Corporation. * Use is subject to license terms. * * Author: Niu Yawei @@ -28,14 +28,8 @@ * lustre/obdclass/lprocfs_jobstats.c */ -#ifndef EXPORT_SYMTAB -# define EXPORT_SYMTAB -#endif #define DEBUG_SUBSYSTEM S_CLASS -#ifndef __KERNEL__ -# include -#endif #include #include @@ -70,13 +64,13 @@ */ struct job_stat { - cfs_hlist_node_t js_hash; - cfs_list_t js_list; - cfs_atomic_t js_refcount; - char js_jobid[JOBSTATS_JOBID_SIZE]; - time_t js_timestamp; /* seconds */ - struct lprocfs_stats *js_stats; - struct obd_job_stats *js_jobstats; + struct hlist_node js_hash; + struct list_head js_list; + atomic_t js_refcount; + char js_jobid[LUSTRE_JOBID_SIZE]; + time_t js_timestamp; /* seconds */ + struct lprocfs_stats *js_stats; + struct obd_job_stats *js_jobstats; }; static unsigned job_stat_hash(cfs_hash_t *hs, const void *key, unsigned mask) @@ -84,31 +78,31 @@ static unsigned job_stat_hash(cfs_hash_t *hs, const void *key, unsigned mask) return cfs_hash_djb2_hash(key, strlen(key), mask); } -static void *job_stat_key(cfs_hlist_node_t *hnode) +static void *job_stat_key(struct hlist_node *hnode) { struct job_stat *job; - job = cfs_hlist_entry(hnode, struct job_stat, js_hash); + job = hlist_entry(hnode, struct job_stat, js_hash); return job->js_jobid; } -static int job_stat_keycmp(const void *key, cfs_hlist_node_t *hnode) +static int job_stat_keycmp(const void *key, struct hlist_node *hnode) { struct job_stat *job; - job = cfs_hlist_entry(hnode, struct job_stat, js_hash); + job = hlist_entry(hnode, struct job_stat, js_hash); return (strlen(job->js_jobid) == strlen(key)) && !strncmp(job->js_jobid, key, strlen(key)); } -static void *job_stat_object(cfs_hlist_node_t *hnode) +static void *job_stat_object(struct hlist_node *hnode) { - return cfs_hlist_entry(hnode, struct job_stat, js_hash); + return hlist_entry(hnode, struct job_stat, js_hash); } -static void job_stat_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static void job_stat_get(cfs_hash_t *hs, struct hlist_node *hnode) { struct job_stat *job; - job = cfs_hlist_entry(hnode, struct job_stat, js_hash); - cfs_atomic_inc(&job->js_refcount); + job = hlist_entry(hnode, struct job_stat, js_hash); + atomic_inc(&job->js_refcount); } static void job_free(struct job_stat *job) @@ -117,7 +111,7 @@ static void job_free(struct job_stat *job) LASSERT(job->js_jobstats); write_lock(&job->js_jobstats->ojs_lock); - cfs_list_del_init(&job->js_list); + list_del_init(&job->js_list); write_unlock(&job->js_jobstats->ojs_lock); lprocfs_free_stats(&job->js_stats); @@ -131,16 +125,16 @@ static void job_putref(struct job_stat *job) job_free(job); } -static void job_stat_put_locked(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static void job_stat_put_locked(cfs_hash_t *hs, struct hlist_node *hnode) { struct job_stat *job; - job = cfs_hlist_entry(hnode, struct job_stat, js_hash); + job = hlist_entry(hnode, struct job_stat, js_hash); job_putref(job); } -static void job_stat_exit(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static void job_stat_exit(cfs_hash_t *hs, struct hlist_node *hnode) { - CERROR("Should not have any items!"); + CERROR("should not have any items\n"); } static cfs_hash_ops_t job_stats_hash_ops = { @@ -154,12 +148,12 @@ static cfs_hash_ops_t job_stats_hash_ops = { }; static int job_iter_callback(cfs_hash_t *hs, cfs_hash_bd_t *bd, - cfs_hlist_node_t *hnode, void *data) + struct hlist_node *hnode, void *data) { time_t oldest = *((time_t *)data); struct job_stat *job; - job = cfs_hlist_entry(hnode, struct job_stat, js_hash); + job = hlist_entry(hnode, struct job_stat, js_hash); if (!oldest || job->js_timestamp < oldest) cfs_hash_bd_del_locked(hs, bd, hnode); @@ -202,12 +196,12 @@ static struct job_stat *job_alloc(char *jobid, struct obd_job_stats *jobs) jobs->ojs_cntr_init_fn(job->js_stats); - memcpy(job->js_jobid, jobid, JOBSTATS_JOBID_SIZE); + memcpy(job->js_jobid, jobid, LUSTRE_JOBID_SIZE); job->js_timestamp = cfs_time_current_sec(); job->js_jobstats = jobs; - CFS_INIT_HLIST_NODE(&job->js_hash); - CFS_INIT_LIST_HEAD(&job->js_list); - cfs_atomic_set(&job->js_refcount, 1); + INIT_HLIST_NODE(&job->js_hash); + INIT_LIST_HEAD(&job->js_list); + atomic_set(&job->js_refcount, 1); return job; } @@ -226,9 +220,9 @@ int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, if (!jobid || !strlen(jobid)) RETURN(-EINVAL); - if (strlen(jobid) >= JOBSTATS_JOBID_SIZE) { + if (strlen(jobid) >= LUSTRE_JOBID_SIZE) { CERROR("Invalid jobid size (%lu), expect(%d)\n", - (unsigned long)strlen(jobid) + 1, JOBSTATS_JOBID_SIZE); + (unsigned long)strlen(jobid) + 1, LUSTRE_JOBID_SIZE); RETURN(-EINVAL); } @@ -245,15 +239,15 @@ int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, if (job2 != job) { job_putref(job); job = job2; - /* We cannot LASSERT(!cfs_list_empty(&job->js_list)) here, + /* We cannot LASSERT(!list_empty(&job->js_list)) here, * since we just lost the race for inserting "job" into the * ojs_list, and some other thread is doing it _right_now_. * Instead, be content the other thread is doing this, since * "job2" was initialized in job_alloc() already. LU-2163 */ } else { - LASSERT(cfs_list_empty(&job->js_list)); + LASSERT(list_empty(&job->js_list)); write_lock(&stats->ojs_lock); - cfs_list_add_tail(&job->js_list, &stats->ojs_list); + list_add_tail(&job->js_list, &stats->ojs_list); write_unlock(&stats->ojs_lock); } @@ -278,7 +272,7 @@ void lprocfs_job_stats_fini(struct obd_device *obd) cfs_hash_for_each_safe(stats->ojs_hash, job_iter_callback, &oldest); cfs_hash_putref(stats->ojs_hash); stats->ojs_hash = NULL; - LASSERT(cfs_list_empty(&stats->ojs_list)); + LASSERT(list_empty(&stats->ojs_list)); } EXPORT_SYMBOL(lprocfs_job_stats_fini); @@ -292,7 +286,7 @@ static void *lprocfs_jobstats_seq_start(struct seq_file *p, loff_t *pos) if (off == 0) return SEQ_START_TOKEN; off--; - cfs_list_for_each_entry(job, &stats->ojs_list, js_list) { + list_for_each_entry(job, &stats->ojs_list, js_list) { if (!off--) return job; } @@ -310,7 +304,7 @@ static void *lprocfs_jobstats_seq_next(struct seq_file *p, void *v, loff_t *pos) { struct obd_job_stats *stats = p->private; struct job_stat *job; - cfs_list_t *next; + struct list_head *next; ++*pos; if (v == SEQ_START_TOKEN) { @@ -321,7 +315,7 @@ static void *lprocfs_jobstats_seq_next(struct seq_file *p, void *v, loff_t *pos) } return next == &stats->ojs_list ? NULL : - cfs_list_entry(next, struct job_stat, js_list); + list_entry(next, struct job_stat, js_list); } /* @@ -369,7 +363,6 @@ static int lprocfs_jobstats_seq_show(struct seq_file *p, void *v) struct job_stat *job = v; struct lprocfs_stats *s; struct lprocfs_counter ret; - struct lprocfs_counter *cntr; struct lprocfs_counter_header *cntr_header; int i; @@ -383,7 +376,6 @@ static int lprocfs_jobstats_seq_show(struct seq_file *p, void *v) s = job->js_stats; for (i = 0; i < s->ls_num; i++) { - cntr = lprocfs_stats_counter_get(s, 0, i); cntr_header = &s->ls_cnt_header[i]; lprocfs_stats_collect(s, i, &ret); @@ -412,7 +404,7 @@ static int lprocfs_jobstats_seq_show(struct seq_file *p, void *v) return 0; } -struct seq_operations lprocfs_jobstats_seq_sops = { +static const struct seq_operations lprocfs_jobstats_seq_sops = { start: lprocfs_jobstats_seq_start, stop: lprocfs_jobstats_seq_stop, next: lprocfs_jobstats_seq_next, @@ -421,44 +413,43 @@ struct seq_operations lprocfs_jobstats_seq_sops = { static int lprocfs_jobstats_seq_open(struct inode *inode, struct file *file) { - struct proc_dir_entry *dp = PDE(inode); struct seq_file *seq; int rc; - if (LPROCFS_ENTRY_AND_CHECK(dp)) + if (LPROCFS_ENTRY_CHECK(PDE(inode))) return -ENOENT; rc = seq_open(file, &lprocfs_jobstats_seq_sops); - if (rc) { - LPROCFS_EXIT(); + if (rc) return rc; - } seq = file->private_data; - seq->private = dp->data; + seq->private = PDE_DATA(inode); return 0; } -static ssize_t lprocfs_jobstats_seq_write(struct file *file, const char *buf, +static ssize_t lprocfs_jobstats_seq_write(struct file *file, + const char __user *buf, size_t len, loff_t *off) { struct seq_file *seq = file->private_data; struct obd_job_stats *stats = seq->private; - char jobid[JOBSTATS_JOBID_SIZE]; + char jobid[LUSTRE_JOBID_SIZE]; int all = 0; struct job_stat *job; - if (!memcmp(buf, "clear", strlen("clear"))) { - all = 1; - } else if (len < JOBSTATS_JOBID_SIZE) { - memset(jobid, 0, JOBSTATS_JOBID_SIZE); - /* Trim '\n' if any */ - if (buf[len - 1] == '\n') - memcpy(jobid, buf, len - 1); - else - memcpy(jobid, buf, len); - } else { + if (len == 0 || len >= LUSTRE_JOBID_SIZE) return -EINVAL; - } + + if (copy_from_user(jobid, buf, len)) + return -EFAULT; + jobid[len] = 0; + + /* Trim '\n' if any */ + if (jobid[len - 1] == '\n') + jobid[len - 1] = 0; + + if (strcmp(jobid, "clear") == 0) + all = 1; LASSERT(stats->ojs_hash); if (all) { @@ -481,7 +472,7 @@ static ssize_t lprocfs_jobstats_seq_write(struct file *file, const char *buf, return len; } -struct file_operations lprocfs_jobstats_seq_fops = { +static const struct file_operations lprocfs_jobstats_seq_fops = { .owner = THIS_MODULE, .open = lprocfs_jobstats_seq_open, .read = seq_read, @@ -519,7 +510,7 @@ int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num, if (stats->ojs_hash == NULL) RETURN(-ENOMEM); - CFS_INIT_LIST_HEAD(&stats->ojs_list); + INIT_LIST_HEAD(&stats->ojs_list); rwlock_init(&stats->ojs_lock); stats->ojs_cntr_num = cntr_num; stats->ojs_cntr_init_fn = init_fn; @@ -527,36 +518,33 @@ int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num, stats->ojs_last_cleanup = cfs_time_current_sec(); LPROCFS_WRITE_ENTRY(); - entry = create_proc_entry("job_stats", 0644, obd->obd_proc_entry); + entry = proc_create_data("job_stats", 0644, obd->obd_proc_entry, + &lprocfs_jobstats_seq_fops, stats); LPROCFS_WRITE_EXIT(); - if (entry) { - entry->proc_fops = &lprocfs_jobstats_seq_fops; - entry->data = stats; - RETURN(0); - } else { + if (entry == NULL) { lprocfs_job_stats_fini(obd); RETURN(-ENOMEM); } + RETURN(0); } EXPORT_SYMBOL(lprocfs_job_stats_init); -int lprocfs_rd_job_interval(char *page, char **start, off_t off, - int count, int *eof, void *data) +int lprocfs_job_interval_seq_show(struct seq_file *m, void *data) { - struct obd_device *obd = (struct obd_device *)data; + struct obd_device *obd = m->private; struct obd_job_stats *stats; LASSERT(obd != NULL); stats = &obd->u.obt.obt_jobstats; - *eof = 1; - return snprintf(page, count, "%d\n", stats->ojs_cleanup_interval); + return seq_printf(m, "%d\n", stats->ojs_cleanup_interval); } -EXPORT_SYMBOL(lprocfs_rd_job_interval); +EXPORT_SYMBOL(lprocfs_job_interval_seq_show); -int lprocfs_wr_job_interval(struct file *file, const char *buffer, - unsigned long count, void *data) +ssize_t +lprocfs_job_interval_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) { - struct obd_device *obd = (struct obd_device *)data; + struct obd_device *obd = ((struct seq_file *)file->private_data)->private; struct obd_job_stats *stats; int val, rc; @@ -569,10 +557,7 @@ int lprocfs_wr_job_interval(struct file *file, const char *buffer, stats->ojs_cleanup_interval = val; lprocfs_job_cleanup(stats, true); - return count; - } -EXPORT_SYMBOL(lprocfs_wr_job_interval); - +EXPORT_SYMBOL(lprocfs_job_interval_seq_write); #endif /* LPROCFS*/