From dc442398aba7d009b9ca05e34c89a90c9ea99048 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Fri, 4 Aug 2017 17:12:24 -0400 Subject: [PATCH] LU-8066 obd: fix LPROC_SEQ_FOPS macros for debugfs While porting to debugfs I discovered a bug in that for the debugfs case no data was being passed into single_open(). This would cause a crash when reading debugfs files since the seq_file private field was NULL. Second change is the rename of the *WO_TYPE* macro to LPROC_SEQ_FOPS_WR_ONLY to match upstream. Change-Id: I9b6baebecaeb82795d7055148533862489473a1d Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/26650 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Emoly Liu Reviewed-by: Dmitry Eremin Reviewed-by: Oleg Drokin --- lustre/fld/lproc_fld.c | 2 +- lustre/include/lprocfs_status.h | 12 +++++++----- lustre/ldlm/ldlm_resource.c | 2 +- lustre/mdc/lproc_mdc.c | 2 +- lustre/mdt/mdt_lproc.c | 6 +++--- lustre/mgc/lproc_mgc.c | 2 +- lustre/mgs/lproc_mgs.c | 2 +- lustre/ofd/lproc_ofd.c | 2 +- lustre/osc/lproc_osc.c | 2 +- lustre/osd-ldiskfs/osd_lproc.c | 2 +- lustre/osd-zfs/osd_lproc.c | 2 +- lustre/osp/lproc_osp.c | 2 +- lustre/ptlrpc/nodemap_lproc.c | 12 ++++++------ lustre/quota/qsd_lib.c | 2 +- 14 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lustre/fld/lproc_fld.c b/lustre/fld/lproc_fld.c index c7be5bf..3a985b3 100644 --- a/lustre/fld/lproc_fld.c +++ b/lustre/fld/lproc_fld.c @@ -137,7 +137,7 @@ lprocfs_cache_flush_seq_write(struct file *file, const char __user *buffer, LPROC_SEQ_FOPS_RO(fld_proc_targets); LPROC_SEQ_FOPS(fld_proc_hash); -LPROC_SEQ_FOPS_WO_TYPE(fld, cache_flush); +LPROC_SEQ_FOPS_WR_ONLY(fld, cache_flush); struct lprocfs_vars fld_client_proc_list[] = { { .name = "targets", diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index 83ede1b..c119ce5 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -669,7 +669,8 @@ static int name##_single_open(struct inode *inode, struct file *file) \ return rc; \ \ return single_open(file, name##_seq_show, \ - inode->i_private ? : PDE_DATA(inode)); \ + inode->i_private ? inode->i_private : \ + PDE_DATA(inode)); \ } \ static const struct file_operations name##_fops = { \ .owner = THIS_MODULE, \ @@ -701,11 +702,11 @@ static const struct file_operations name##_fops = { \ { \ struct seq_file *seq = file->private_data; \ return lprocfs_##type##_seq_write(file, buffer, \ - count, seq->private); \ + count, seq->private); \ } \ LPROC_SEQ_FOPS(name##_##type); -#define LPROC_SEQ_FOPS_WO_TYPE(name, type) \ +#define LPROC_SEQ_FOPS_WR_ONLY(name, type) \ static ssize_t name##_##type##_write(struct file *file, \ const char __user *buffer, size_t count, \ loff_t *off) \ @@ -715,7 +716,8 @@ static const struct file_operations name##_fops = { \ static int name##_##type##_open(struct inode *inode, struct file *file)\ { \ return single_open(file, NULL, \ - inode->i_private ? : PDE_DATA(inode));\ + inode->i_private ? inode->i_private : \ + PDE_DATA(inode)); \ } \ static const struct file_operations name##_##type##_fops = { \ .open = name##_##type##_open, \ @@ -975,7 +977,7 @@ u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx, #define LPROC_SEQ_FOPS(name) #define LPROC_SEQ_FOPS_RO_TYPE(name, type) #define LPROC_SEQ_FOPS_RW_TYPE(name, type) -#define LPROC_SEQ_FOPS_WO_TYPE(name, type) +#define LPROC_SEQ_FOPS_WR_ONLY(name, type) /* lprocfs_jobstats.c */ static inline diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 70b6f39..ee4dac1 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -75,7 +75,7 @@ lprocfs_dump_ns_seq_write(struct file *file, const char __user *buffer, ldlm_dump_all_namespaces(LDLM_NAMESPACE_CLIENT, D_DLMTRACE); RETURN(count); } -LPROC_SEQ_FOPS_WO_TYPE(ldlm, dump_ns); +LPROC_SEQ_FOPS_WR_ONLY(ldlm, dump_ns); LPROC_SEQ_FOPS_RW_TYPE(ldlm_rw, uint); diff --git a/lustre/mdc/lproc_mdc.c b/lustre/mdc/lproc_mdc.c index 9a6d707..f9818e3 100644 --- a/lustre/mdc/lproc_mdc.c +++ b/lustre/mdc/lproc_mdc.c @@ -166,7 +166,7 @@ static ssize_t mdc_rpc_stats_seq_write(struct file *file, } LPROC_SEQ_FOPS(mdc_rpc_stats); -LPROC_SEQ_FOPS_WO_TYPE(mdc, ping); +LPROC_SEQ_FOPS_WR_ONLY(mdc, ping); LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags); LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid); diff --git a/lustre/mdt/mdt_lproc.c b/lustre/mdt/mdt_lproc.c index 0c70243..d0b37fb 100644 --- a/lustre/mdt/mdt_lproc.c +++ b/lustre/mdt/mdt_lproc.c @@ -348,7 +348,7 @@ lprocfs_identity_flush_seq_write(struct file *file, const char __user *buffer, mdt_flush_identity(mdt->mdt_identity_cache, uid); return count; } -LPROC_SEQ_FOPS_WO_TYPE(mdt, identity_flush); +LPROC_SEQ_FOPS_WR_ONLY(mdt, identity_flush); static ssize_t lprocfs_identity_info_seq_write(struct file *file, const char __user *buffer, @@ -416,7 +416,7 @@ out: return rc ? rc : count; } -LPROC_SEQ_FOPS_WO_TYPE(mdt, identity_info); +LPROC_SEQ_FOPS_WR_ONLY(mdt, identity_info); static int mdt_site_stats_seq_show(struct seq_file *m, void *data) { @@ -766,7 +766,7 @@ LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status); LPROC_SEQ_FOPS_RO_TYPE(mdt, num_exports); LPROC_SEQ_FOPS_RO_TYPE(mdt, target_instance); LPROC_SEQ_FOPS_RO_TYPE(mdt, hash); -LPROC_SEQ_FOPS_WO_TYPE(mdt, mds_evict_client); +LPROC_SEQ_FOPS_WR_ONLY(mdt, mds_evict_client); LPROC_SEQ_FOPS_RW_TYPE(mdt, job_interval); LPROC_SEQ_FOPS_RW_TYPE(mdt, ir_factor); LPROC_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear); diff --git a/lustre/mgc/lproc_mgc.c b/lustre/mgc/lproc_mgc.c index 7486d1c..4bb3927 100644 --- a/lustre/mgc/lproc_mgc.c +++ b/lustre/mgc/lproc_mgc.c @@ -45,7 +45,7 @@ LPROC_SEQ_FOPS_RO_TYPE(mgc, conn_uuid); LPROC_SEQ_FOPS_RO_TYPE(mgc, import); LPROC_SEQ_FOPS_RO_TYPE(mgc, state); -LPROC_SEQ_FOPS_WO_TYPE(mgc, ping); +LPROC_SEQ_FOPS_WR_ONLY(mgc, ping); static int mgc_ir_state_seq_show(struct seq_file *m, void *v) { diff --git a/lustre/mgs/lproc_mgs.c b/lustre/mgs/lproc_mgs.c index aecb740..7fafade 100644 --- a/lustre/mgs/lproc_mgs.c +++ b/lustre/mgs/lproc_mgs.c @@ -204,7 +204,7 @@ int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb) LPROC_SEQ_FOPS_RO_TYPE(mgs, num_exports); LPROC_SEQ_FOPS_RO_TYPE(mgs, hash); -LPROC_SEQ_FOPS_WO_TYPE(mgs, evict_client); +LPROC_SEQ_FOPS_WR_ONLY(mgs, evict_client); LPROC_SEQ_FOPS_RW_TYPE(mgs, ir_timeout); static struct lprocfs_vars lprocfs_mgs_obd_vars[] = { diff --git a/lustre/ofd/lproc_ofd.c b/lustre/ofd/lproc_ofd.c index 08d8a69..b23eda2 100644 --- a/lustre/ofd/lproc_ofd.c +++ b/lustre/ofd/lproc_ofd.c @@ -891,7 +891,7 @@ LPROC_SEQ_FOPS_RO(ofd_site_stats); LPROC_SEQ_FOPS_RO_TYPE(ofd, recovery_status); LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_soft); LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_hard); -LPROC_SEQ_FOPS_WO_TYPE(ofd, evict_client); +LPROC_SEQ_FOPS_WR_ONLY(ofd, evict_client); LPROC_SEQ_FOPS_RO_TYPE(ofd, num_exports); LPROC_SEQ_FOPS_RO_TYPE(ofd, target_instance); LPROC_SEQ_FOPS_RW_TYPE(ofd, ir_factor); diff --git a/lustre/osc/lproc_osc.c b/lustre/osc/lproc_osc.c index fa780718..b1aa09b 100644 --- a/lustre/osc/lproc_osc.c +++ b/lustre/osc/lproc_osc.c @@ -597,7 +597,7 @@ LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid); LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts); LPROC_SEQ_FOPS_RO_TYPE(osc, state); -LPROC_SEQ_FOPS_WO_TYPE(osc, ping); +LPROC_SEQ_FOPS_WR_ONLY(osc, ping); LPROC_SEQ_FOPS_RW_TYPE(osc, import); LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov); diff --git a/lustre/osd-ldiskfs/osd_lproc.c b/lustre/osd-ldiskfs/osd_lproc.c index dccec1b..5a3c703 100644 --- a/lustre/osd-ldiskfs/osd_lproc.c +++ b/lustre/osd-ldiskfs/osd_lproc.c @@ -350,7 +350,7 @@ lprocfs_osd_force_sync_seq_write(struct file *file, const char __user *buffer, return rc == 0 ? count : rc; } -LPROC_SEQ_FOPS_WO_TYPE(ldiskfs, osd_force_sync); +LPROC_SEQ_FOPS_WR_ONLY(ldiskfs, osd_force_sync); static int ldiskfs_osd_pdo_seq_show(struct seq_file *m, void *data) { diff --git a/lustre/osd-zfs/osd_lproc.c b/lustre/osd-zfs/osd_lproc.c index 89f0f160..f24406f 100644 --- a/lustre/osd-zfs/osd_lproc.c +++ b/lustre/osd-zfs/osd_lproc.c @@ -244,7 +244,7 @@ lprocfs_osd_force_sync_seq_write(struct file *file, const char __user *buffer, return rc == 0 ? count : rc; } -LPROC_SEQ_FOPS_WO_TYPE(zfs, osd_force_sync); +LPROC_SEQ_FOPS_WR_ONLY(zfs, osd_force_sync); LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_blksize); LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_kbytestotal); diff --git a/lustre/osp/lproc_osp.c b/lustre/osp/lproc_osp.c index 862b2bf..d88646b 100644 --- a/lustre/osp/lproc_osp.c +++ b/lustre/osp/lproc_osp.c @@ -744,7 +744,7 @@ osp_lfsck_max_rpcs_in_flight_seq_write(struct file *file, } LPROC_SEQ_FOPS(osp_lfsck_max_rpcs_in_flight); -LPROC_SEQ_FOPS_WO_TYPE(osp, ping); +LPROC_SEQ_FOPS_WR_ONLY(osp, ping); LPROC_SEQ_FOPS_RO_TYPE(osp, connect_flags); LPROC_SEQ_FOPS_RO_TYPE(osp, server_uuid); LPROC_SEQ_FOPS_RO_TYPE(osp, conn_uuid); diff --git a/lustre/ptlrpc/nodemap_lproc.c b/lustre/ptlrpc/nodemap_lproc.c index 6da0fd3..fc13b00 100644 --- a/lustre/ptlrpc/nodemap_lproc.c +++ b/lustre/ptlrpc/nodemap_lproc.c @@ -756,7 +756,7 @@ lprocfs_add_nodemap_seq_write(struct file *file, const char __user *buffer, return rc; } -LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap); +LPROC_SEQ_FOPS_WR_ONLY(nodemap, add_nodemap); /** * Delete a nodemap. @@ -800,7 +800,7 @@ lprocfs_del_nodemap_seq_write(struct file *file, const char __user *buffer, return rc; } -LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap); +LPROC_SEQ_FOPS_WR_ONLY(nodemap, del_nodemap); /** * Helper function to parse a NID string. @@ -897,7 +897,7 @@ lprocfs_add_nodemap_range_seq_write(struct file *file, out: return rc; } -LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_range); +LPROC_SEQ_FOPS_WR_ONLY(nodemap, add_nodemap_range); /** * Delete a NID range from nodemap. @@ -956,7 +956,7 @@ lprocfs_del_nodemap_range_seq_write(struct file *file, out: return rc; } -LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_range); +LPROC_SEQ_FOPS_WR_ONLY(nodemap, del_nodemap_range); /** * Add an idmap to nodemap. @@ -1025,7 +1025,7 @@ lprocfs_add_nodemap_idmap_seq_write(struct file *file, out: return rc; } -LPROC_SEQ_FOPS_WO_TYPE(nodemap, add_nodemap_idmap); +LPROC_SEQ_FOPS_WR_ONLY(nodemap, add_nodemap_idmap); /** * Delete an idmap from nodemap. @@ -1094,7 +1094,7 @@ lprocfs_del_nodemap_idmap_seq_write(struct file *file, out: return rc; } -LPROC_SEQ_FOPS_WO_TYPE(nodemap, del_nodemap_idmap); +LPROC_SEQ_FOPS_WR_ONLY(nodemap, del_nodemap_idmap); #endif /* NODEMAP_PROC_DEBUG */ static struct lprocfs_vars lprocfs_nm_module_vars[] = { diff --git a/lustre/quota/qsd_lib.c b/lustre/quota/qsd_lib.c index f4c37e6..cb5d6d5 100644 --- a/lustre/quota/qsd_lib.c +++ b/lustre/quota/qsd_lib.c @@ -188,7 +188,7 @@ lprocfs_force_reint_seq_write(struct file *file, const char __user *buffer, } return rc == 0 ? count : rc; } -LPROC_SEQ_FOPS_WO_TYPE(qsd, force_reint); +LPROC_SEQ_FOPS_WR_ONLY(qsd, force_reint); static int qsd_timeout_seq_show(struct seq_file *m, void *data) { -- 1.8.3.1