From 794a5c02ebeb4eb2e9490e4f16cafcc9bf075e7b Mon Sep 17 00:00:00 2001 From: James Simmons Date: Wed, 23 Apr 2014 09:31:09 -0400 Subject: [PATCH] LU-3319 procfs: update zfs proc handling to seq_files Migrate all zfs proc handling to using strictly seq_files. Signed-off-by: James Simmons Change-Id: I6dc7e65c3e74e7934a17939815ec3c334fac58c7 Reviewed-on: http://review.whamcloud.com/7934 Tested-by: Jenkins Reviewed-by: Bob Glossman Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Yang Sheng --- lustre/osd-zfs/osd_handler.c | 13 +++--- lustre/osd-zfs/osd_internal.h | 3 +- lustre/osd-zfs/osd_lproc.c | 92 +++++++++++++++++++++++++------------------ 3 files changed, 61 insertions(+), 47 deletions(-) diff --git a/lustre/osd-zfs/osd_handler.c b/lustre/osd-zfs/osd_handler.c index 42e6e20..83b243d 100644 --- a/lustre/osd-zfs/osd_handler.c +++ b/lustre/osd-zfs/osd_handler.c @@ -761,12 +761,13 @@ static int osd_process_config(const struct lu_env *env, break; case LCFG_PARAM: { LASSERT(&o->od_dt_dev); - rc = class_process_proc_param(PARAM_OSD, lprocfs_osd_obd_vars, - cfg, &o->od_dt_dev); + rc = class_process_proc_seq_param(PARAM_OSD, + lprocfs_osd_obd_vars, cfg, + &o->od_dt_dev); if (rc > 0 || rc == -ENOSYS) - rc = class_process_proc_param(PARAM_OST, - lprocfs_osd_obd_vars, - cfg, &o->od_dt_dev); + rc = class_process_proc_seq_param(PARAM_OST, + lprocfs_osd_obd_vars, + cfg, &o->od_dt_dev); break; } default: @@ -923,7 +924,7 @@ int __init osd_init(void) rc = class_register_type(&osd_obd_device_ops, NULL, true, NULL, #ifndef HAVE_ONLY_PROCFS_SEQ - lprocfs_osd_module_vars, + NULL, #endif LUSTRE_OSD_ZFS_NAME, &osd_device_type); if (rc) diff --git a/lustre/osd-zfs/osd_internal.h b/lustre/osd-zfs/osd_internal.h index c53ad8b..1773313 100644 --- a/lustre/osd-zfs/osd_internal.h +++ b/lustre/osd-zfs/osd_internal.h @@ -405,8 +405,7 @@ enum { }; /* osd_lproc.c */ -extern struct lprocfs_vars lprocfs_osd_obd_vars[]; -extern struct lprocfs_vars lprocfs_osd_module_vars[]; +extern struct lprocfs_seq_vars lprocfs_osd_obd_vars[]; int osd_procfs_init(struct osd_device *osd, const char *name); int osd_procfs_fini(struct osd_device *osd); diff --git a/lustre/osd-zfs/osd_lproc.c b/lustre/osd-zfs/osd_lproc.c index bc8a807..f19ed11 100644 --- a/lustre/osd-zfs/osd_lproc.c +++ b/lustre/osd-zfs/osd_lproc.c @@ -107,27 +107,27 @@ out: RETURN(result); } -static int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int zfs_osd_fstype_seq_show(struct seq_file *m, void *data) { - return snprintf(page, count, "zfs\n"); + return seq_printf(m, "zfs\n"); } +LPROC_SEQ_FOPS_RO(zfs_osd_fstype); -static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int zfs_osd_mntdev_seq_show(struct seq_file *m, void *data) { - struct osd_device *osd = osd_dt_dev((struct dt_device *)data); + struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private); LASSERT(osd != NULL); - *eof = 1; - - return snprintf(page, count, "%s\n", osd->od_mntdev); + return seq_printf(m, "%s\n", osd->od_mntdev); } +LPROC_SEQ_FOPS_RO(zfs_osd_mntdev); -static int lprocfs_osd_wr_force_sync(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t +lprocfs_osd_force_sync_seq_write(struct file *file, const char __user *buffer, + size_t count, loff_t *off) { - struct dt_device *dt = data; + struct seq_file *m = file->private_data; + struct dt_device *dt = m->private; struct lu_env env; int rc; @@ -139,21 +139,23 @@ static int lprocfs_osd_wr_force_sync(struct file *file, const char *buffer, return rc == 0 ? count : rc; } +LPROC_SEQ_FOPS_WO_TYPE(zfs, osd_force_sync); -static int lprocfs_osd_rd_iused_est(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int zfs_osd_iused_est_seq_show(struct seq_file *m, void *data) { - struct osd_device *osd = osd_dt_dev((struct dt_device *)data); + struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private); LASSERT(osd != NULL); - return snprintf(page, count, "%d\n", osd->od_quota_iused_est); + return seq_printf(m, "%d\n", osd->od_quota_iused_est); } -static int lprocfs_osd_wr_iused_est(struct file *file, - const char __user *buffer, - unsigned long count, void *data) +static ssize_t +zfs_osd_iused_est_seq_write(struct file *file, const char __user *buffer, + size_t count, loff_t *off) { - struct osd_device *osd = osd_dt_dev((struct dt_device *)data); + struct seq_file *m = file->private_data; + struct dt_device *dt = m->private; + struct osd_device *osd = osd_dt_dev(dt); int rc, val; LASSERT(osd != NULL); @@ -166,24 +168,36 @@ static int lprocfs_osd_wr_iused_est(struct file *file, return count; } - -struct lprocfs_vars lprocfs_osd_obd_vars[] = { - { "blocksize", lprocfs_dt_rd_blksize, 0, 0 }, - { "kbytestotal", lprocfs_dt_rd_kbytestotal, 0, 0 }, - { "kbytesfree", lprocfs_dt_rd_kbytesfree, 0, 0 }, - { "kbytesavail", lprocfs_dt_rd_kbytesavail, 0, 0 }, - { "filestotal", lprocfs_dt_rd_filestotal, 0, 0 }, - { "filesfree", lprocfs_dt_rd_filesfree, 0, 0 }, - { "fstype", lprocfs_osd_rd_fstype, 0, 0 }, - { "mntdev", lprocfs_osd_rd_mntdev, 0, 0 }, - { "force_sync", 0, lprocfs_osd_wr_force_sync }, - { "quota_iused_estimate", lprocfs_osd_rd_iused_est, - lprocfs_osd_wr_iused_est, 0, 0 }, - { 0 } -}; - -struct lprocfs_vars lprocfs_osd_module_vars[] = { - { "num_refs", lprocfs_rd_numrefs, 0, 0 }, +LPROC_SEQ_FOPS(zfs_osd_iused_est); + +LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_blksize); +LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_kbytestotal); +LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_kbytesfree); +LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_kbytesavail); +LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_filestotal); +LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_filesfree); + +struct lprocfs_seq_vars lprocfs_osd_obd_vars[] = { + { .name = "blocksize", + .fops = &zfs_dt_blksize_fops }, + { .name = "kbytestotal", + .fops = &zfs_dt_kbytestotal_fops }, + { .name = "kbytesfree", + .fops = &zfs_dt_kbytesfree_fops }, + { .name = "kbytesavail", + .fops = &zfs_dt_kbytesavail_fops }, + { .name = "filestotal", + .fops = &zfs_dt_filestotal_fops }, + { .name = "filesfree", + .fops = &zfs_dt_filesfree_fops }, + { .name = "fstype", + .fops = &zfs_osd_fstype_fops }, + { .name = "mntdev", + .fops = &zfs_osd_mntdev_fops }, + { .name = "force_sync", + .fops = &zfs_osd_force_sync_fops }, + { .name = "quota_iused_estimate", + .fops = &zfs_osd_iused_est_fops }, { 0 } }; @@ -203,7 +217,7 @@ int osd_procfs_init(struct osd_device *osd, const char *name) LASSERT(name != NULL); LASSERT(type != NULL); - osd->od_proc_entry = lprocfs_register(name, type->typ_procroot, + osd->od_proc_entry = lprocfs_seq_register(name, type->typ_procroot, lprocfs_osd_obd_vars, &osd->od_dt_dev); if (IS_ERR(osd->od_proc_entry)) { rc = PTR_ERR(osd->od_proc_entry); -- 1.8.3.1