From: James Simmons Date: Thu, 14 Nov 2013 14:53:50 +0000 (-0500) Subject: LU-3319 procfs: migrate quota proc handling to seq_files X-Git-Tag: 2.5.53~42 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=8b5814bbbb95efe440ff921506d9214ae3261b6e LU-3319 procfs: migrate quota proc handling to seq_files For proper 3.10+ kernel support we migrate the quota proc file handling to use only seq_files. Signed-off-by: James Simmons Change-Id: I50b1e5372dfad4e06f7e4dec95cc3efa83a3f902 Reviewed-on: http://review.whamcloud.com/7931 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Johann Lombardi Reviewed-by: Bob Glossman --- diff --git a/lustre/quota/lproc_quota.c b/lustre/quota/lproc_quota.c index 791f47d..1e9f785 100644 --- a/lustre/quota/lproc_quota.c +++ b/lustre/quota/lproc_quota.c @@ -253,7 +253,6 @@ struct seq_operations lprocfs_quota_seq_sops = { static int lprocfs_quota_seq_open(struct inode *inode, struct file *file) { - struct proc_dir_entry *dp = PDE(inode); struct seq_file *seq; int rc; struct lquota_procfs *lqp; @@ -265,7 +264,7 @@ static int lprocfs_quota_seq_open(struct inode *inode, struct file *file) return -ENOMEM; /* store pointer to object we would like to iterate over */ - lqp->lqp_obj = (struct dt_object *)dp->data; + lqp->lqp_obj = (struct dt_object *)PDE_DATA(inode); /* Initialize the common environment to be used in the seq operations */ rc = lu_env_init(&lqp->lqp_env, LCT_LOCAL); @@ -280,7 +279,7 @@ static int lprocfs_quota_seq_open(struct inode *inode, struct file *file) goto out_lqp; } - if (LPROCFS_ENTRY_CHECK(dp)) { + if (LPROCFS_ENTRY_CHECK(PDE(inode))) { rc = -ENOENT; goto out_env; } diff --git a/lustre/quota/qmt_dev.c b/lustre/quota/qmt_dev.c index 012b11d..02ec55b 100644 --- a/lustre/quota/qmt_dev.c +++ b/lustre/quota/qmt_dev.c @@ -252,8 +252,8 @@ static int qmt_device_init0(const struct lu_env *env, struct qmt_device *qmt, LASSERT(type != NULL); /* register proc directory associated with this qmt */ - qmt->qmt_proc = lprocfs_register(qmt->qmt_svname, type->typ_procroot, - NULL, NULL); + qmt->qmt_proc = lprocfs_seq_register(qmt->qmt_svname, type->typ_procroot, + NULL, NULL); if (IS_ERR(qmt->qmt_proc)) { rc = PTR_ERR(qmt->qmt_proc); CERROR("%s: failed to create qmt proc entry (%d)\n", diff --git a/lustre/quota/qmt_pool.c b/lustre/quota/qmt_pool.c index 92f6d70..afd450c 100644 --- a/lustre/quota/qmt_pool.c +++ b/lustre/quota/qmt_pool.c @@ -141,40 +141,37 @@ static cfs_hash_ops_t qpi_hash_ops = { }; /* some procfs helpers */ -static int lprocfs_qpi_rd_state(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int qpi_state_seq_show(struct seq_file *m, void *data) { - struct qmt_pool_info *pool = (struct qmt_pool_info *)data; - int type, i = 0; + struct qmt_pool_info *pool = m->private; + int type; LASSERT(pool != NULL); - i = snprintf(page, count, - "pool:\n" - " id: %u\n" - " type: %s\n" - " ref: %d\n" - " least qunit: %lu\n", - pool->qpi_key & 0x0000ffff, - RES_NAME(pool->qpi_key >> 16), - cfs_atomic_read(&pool->qpi_ref), - pool->qpi_least_qunit); - + seq_printf(m, "pool:\n" + " id: %u\n" + " type: %s\n" + " ref: %d\n" + " least qunit: %lu\n", + pool->qpi_key & 0x0000ffff, + RES_NAME(pool->qpi_key >> 16), + cfs_atomic_read(&pool->qpi_ref), + pool->qpi_least_qunit); for (type = 0; type < MAXQUOTAS; type++) - i += snprintf(page + i, count - i, - " %s:\n" - " #slv: %d\n" - " #lqe: %d\n", - QTYPE_NAME(type), - pool->qpi_slv_nr[type], + seq_printf(m, " %s:\n" + " #slv: %d\n" + " #lqe: %d\n", + QTYPE_NAME(type), + pool->qpi_slv_nr[type], cfs_atomic_read(&pool->qpi_site[type]->lqs_hash->hs_count)); - return i; + return 0; } +LPROC_SEQ_FOPS_RO(qpi_state); -static struct lprocfs_vars lprocfs_quota_qpi_vars[] = { - { "info", lprocfs_qpi_rd_state, 0, 0}, +static struct lprocfs_seq_vars lprocfs_quota_qpi_vars[] = { + { "info", &qpi_state_fops }, { NULL } }; @@ -215,8 +212,8 @@ static int qmt_pool_alloc(const struct lu_env *env, struct qmt_device *qmt, /* create pool proc directory */ sprintf(qti->qti_buf, "%s-0x%x", RES_NAME(pool_type), pool_id); - pool->qpi_proc = lprocfs_register(qti->qti_buf, qmt->qmt_proc, - lprocfs_quota_qpi_vars, pool); + pool->qpi_proc = lprocfs_seq_register(qti->qti_buf, qmt->qmt_proc, + lprocfs_quota_qpi_vars, pool); if (IS_ERR(pool->qpi_proc)) { rc = PTR_ERR(pool->qpi_proc); CERROR("%s: failed to create proc entry for pool %s (%d)\n", diff --git a/lustre/quota/qsd_lib.c b/lustre/quota/qsd_lib.c index 253f6b4..d1ef8393 100644 --- a/lustre/quota/qsd_lib.c +++ b/lustre/quota/qsd_lib.c @@ -73,10 +73,9 @@ LU_CONTEXT_KEY_DEFINE(qsd, LCT_MD_THREAD | LCT_DT_THREAD | LCT_LOCAL); LU_KEY_INIT_GENERIC(qsd); /* some procfs helpers */ -static int lprocfs_qsd_rd_state(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int qsd_state_seq_show(struct seq_file *m, void *data) { - struct qsd_instance *qsd = (struct qsd_instance *)data; + struct qsd_instance *qsd = m->private; char enabled[5]; int rc; @@ -90,15 +89,14 @@ static int lprocfs_qsd_rd_state(char *page, char **start, off_t off, if (strlen(enabled) == 0) strcat(enabled, "none"); - rc = snprintf(page, count, - "target name: %s\n" - "pool ID: %d\n" - "type: %s\n" - "quota enabled: %s\n" - "conn to master: %s\n", - qsd->qsd_svname, qsd->qsd_pool_id, - qsd->qsd_is_md ? "md" : "dt", enabled, - qsd->qsd_exp_valid ? "setup" : "not setup yet"); + rc = seq_printf(m, "target name: %s\n" + "pool ID: %d\n" + "type: %s\n" + "quota enabled: %s\n" + "conn to master: %s\n", + qsd->qsd_svname, qsd->qsd_pool_id, + qsd->qsd_is_md ? "md" : "dt", enabled, + qsd->qsd_exp_valid ? "setup" : "not setup yet"); if (qsd->qsd_prepared) { memset(enabled, 0, sizeof(enabled)); @@ -108,8 +106,7 @@ static int lprocfs_qsd_rd_state(char *page, char **start, off_t off, strcat(enabled, "g"); if (strlen(enabled) == 0) strcat(enabled, "none"); - rc += snprintf(page + rc, count - rc, - "space acct: %s\n" + rc += seq_printf(m, "space acct: %s\n" "user uptodate: glb[%d],slv[%d],reint[%d]\n" "group uptodate: glb[%d],slv[%d],reint[%d]\n", enabled, @@ -122,11 +119,11 @@ static int lprocfs_qsd_rd_state(char *page, char **start, off_t off, } return rc; } +LPROC_SEQ_FOPS_RO(qsd_state); -static int lprocfs_qsd_rd_enabled(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int qsd_enabled_seq_show(struct seq_file *m, void *data) { - struct qsd_instance *qsd = (struct qsd_instance *)data; + struct qsd_instance *qsd = m->private; char enabled[5]; LASSERT(qsd != NULL); @@ -139,16 +136,18 @@ static int lprocfs_qsd_rd_enabled(char *page, char **start, off_t off, if (strlen(enabled) == 0) strcat(enabled, "none"); - return snprintf(page, count, "%s\n", enabled); + return seq_printf(m, "%s\n", enabled); } +LPROC_SEQ_FOPS_RO(qsd_enabled); /* force reintegration procedure to be executed. * Used for test/debugging purpose */ -static int lprocfs_qsd_wr_force_reint(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t +lprocfs_force_reint_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) { - struct qsd_instance *qsd = (struct qsd_instance *)data; - int rc = 0, qtype; + struct qsd_instance *qsd = ((struct seq_file *)file->private_data)->private; + int rc = 0, qtype; LASSERT(qsd != NULL); @@ -179,21 +178,22 @@ static int lprocfs_qsd_wr_force_reint(struct file *file, const char *buffer, } return rc == 0 ? count : rc; } +LPROC_SEQ_FOPS_WO_TYPE(qsd, force_reint); -static int lprocfs_qsd_rd_timeout(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int qsd_timeout_seq_show(struct seq_file *m, void *data) { - struct qsd_instance *qsd = (struct qsd_instance *)data; + struct qsd_instance *qsd = m->private; LASSERT(qsd != NULL); - return snprintf(page, count, "%d\n", qsd_wait_timeout(qsd)); + return seq_printf(m, "%d\n", qsd_wait_timeout(qsd)); } -static int lprocfs_qsd_wr_timeout(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t +qsd_timeout_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) { - struct qsd_instance *qsd = (struct qsd_instance *)data; - int timeout, rc; + struct qsd_instance *qsd = ((struct seq_file *)file->private_data)->private; + int timeout, rc; LASSERT(qsd != NULL); rc = lprocfs_write_helper(buffer, count, &timeout); @@ -205,12 +205,13 @@ static int lprocfs_qsd_wr_timeout(struct file *file, const char *buffer, qsd->qsd_timeout = timeout; return count; } +LPROC_SEQ_FOPS(qsd_timeout); -static struct lprocfs_vars lprocfs_quota_qsd_vars[] = { - { "info", lprocfs_qsd_rd_state, 0, 0}, - { "enabled", lprocfs_qsd_rd_enabled, 0, 0}, - { "force_reint", 0, lprocfs_qsd_wr_force_reint, 0}, - { "timeout", lprocfs_qsd_rd_timeout, lprocfs_qsd_wr_timeout, 0}, +static struct lprocfs_seq_vars lprocfs_quota_qsd_vars[] = { + { "info", &qsd_state_fops }, + { "enabled", &qsd_enabled_fops }, + { "force_reint", &qsd_force_reint_fops }, + { "timeout", &qsd_timeout_fops }, { NULL } }; @@ -588,8 +589,8 @@ struct qsd_instance *qsd_init(const struct lu_env *env, char *svname, up(&qsd->qsd_fsinfo->qfs_sem); /* register procfs directory */ - qsd->qsd_proc = lprocfs_register(QSD_DIR, osd_proc, - lprocfs_quota_qsd_vars, qsd); + qsd->qsd_proc = lprocfs_seq_register(QSD_DIR, osd_proc, + lprocfs_quota_qsd_vars, qsd); if (IS_ERR(qsd->qsd_proc)) { rc = PTR_ERR(qsd->qsd_proc); qsd->qsd_proc = NULL;