From 13cd0f9f667c6e138a8cb235d4920f8b749cb154 Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Thu, 15 Apr 2021 08:07:50 -0400 Subject: [PATCH] LU-13344 libcfs: Abstract proc_fs with proc_ops Linux 5.6 introduces proc_ops with v5.5-8862-gd56c0d45f0e2 proc: decouple proc from VFS with "struct proc_ops" Map proc_ops and it's members to file_operations and the appropriate members for older kernels. One remaining 'PROC_OWNER()' macro is left to deal with proc_ops being unable to sensibly map the owner member. Test-Parameters: trivial HPE-bug-id: LUS-8589 Signed-off-by: Shaun Tancheff Change-Id: I3d8940a91b331c4f6bb31a9432194cc082c9cecd Reviewed-on: https://review.whamcloud.com/37873 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- .gitignore | 1 + libcfs/autoconf/lustre-libcfs.m4 | 39 ++++++++++++++++++++++-- libcfs/include/libcfs/linux/linux-fs.h | 17 +++++++++++ lustre/include/lprocfs_status.h | 33 ++++++++++---------- lustre/lmv/lproc_lmv.c | 12 ++++---- lustre/lod/lod_pool.c | 3 +- lustre/lod/lproc_lod.c | 24 +++++++-------- lustre/lov/lov_pool.c | 11 +++---- lustre/lov/lproc_lov.c | 12 ++++---- lustre/mdt/mdt_fs.c | 14 +++++---- lustre/mgs/lproc_mgs.c | 4 +-- lustre/obdclass/lprocfs_jobstats.c | 14 ++++----- lustre/obdclass/lprocfs_status.c | 55 ++++++++++++++++++---------------- lustre/ptlrpc/nodemap_lproc.c | 6 ++-- lustre/quota/lproc_quota.c | 12 ++++---- lustre/quota/lquota_internal.h | 2 +- 16 files changed, 160 insertions(+), 99 deletions(-) diff --git a/.gitignore b/.gitignore index 8b52cf5..d9d43e0 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ *.so *.swp *.unsigned +_lpb 00[0-9][0-9]-*.patch autoMakefile autoMakefile.in diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index a4abdd2..e6bfe10 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -1301,6 +1301,32 @@ LB_CHECK_EXPORT([kallsyms_lookup_name], [kernel/kallsyms.c], ]) # LIBCFS_KALLSYMS_LOOKUP # +# LIBCFS_HAVE_PROC_OPS +# +# v5.5-8862-gd56c0d45f0e2 +# proc: decouple proc from VFS with "struct proc_ops" +# +AC_DEFUN([LIBCFS_SRC_HAVE_PROC_OPS], [ + LB2_LINUX_TEST_SRC([proc_ops], [ + #include + + static struct proc_ops *my_proc; + ],[ + my_proc->proc_lseek = NULL; + ],[-Werror]) +]) +AC_DEFUN([LIBCFS_HAVE_PROC_OPS], [ + AC_MSG_CHECKING([if struct proc_ops exists]) + LB2_LINUX_TEST_RESULT([proc_ops], [ + AC_DEFINE(HAVE_PROC_OPS, 1, + [struct proc_ops exists]) + AC_MSG_RESULT(yes) + ],[ + AC_MSG_RESULT(no) + ]) +]) # LIBCFS_HAVE_PROC_OPS + +# # LIBCFS_VMALLOC_2ARGS # # kernel v5.8-rc1~201^2~19 @@ -1398,8 +1424,17 @@ kfree_sensitive_exists, [ EXTRA_KCFLAGS="$tmp_flags" ]) # LIBCFS_HAVE_NR_UNSTABLE_NFS -AC_DEFUN([LIBCFS_PROG_LINUX_SRC], [] ) -AC_DEFUN([LIBCFS_PROG_LINUX_RESULTS], []) +AC_DEFUN([LIBCFS_PROG_LINUX_SRC], [ + LIBCFS_SRC_HAVE_PROC_OPS + + AC_MSG_CHECKING([for available kernel interfaces to libcfs]) + LB2_LINUX_TEST_COMPILE_ALL([libcfs]) + AC_MSG_RESULT([done]) +]) +AC_DEFUN([LIBCFS_PROG_LINUX_RESULTS], [ + # 5.6 + LIBCFS_HAVE_PROC_OPS +]) # # LIBCFS_PROG_LINUX diff --git a/libcfs/include/libcfs/linux/linux-fs.h b/libcfs/include/libcfs/linux/linux-fs.h index a5beff2..78a75c7 100644 --- a/libcfs/include/libcfs/linux/linux-fs.h +++ b/libcfs/include/libcfs/linux/linux-fs.h @@ -60,4 +60,21 @@ static inline struct dentry *file_dentry(const struct file *file) #define DTTOIF(dirtype) ((dirtype) << S_DT_SHIFT) #endif +#ifdef HAVE_PROC_OPS +#define PROC_OWNER(_fn) +#else +#define proc_ops file_operations +#define PROC_OWNER(_owner) .owner = (_owner), +#define proc_open open +#define proc_read read +#define proc_write write +#define proc_lseek llseek +#define proc_release release +#define proc_poll poll +#define proc_ioctl unlocked_ioctl +#define proc_compat_ioctl compat_ioctl +#define proc_mmap mmap +#define proc_get_unmapped_area get_unmapped_area +#endif + #endif diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index c69546c..d0ab7e1 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -46,6 +46,7 @@ #include #include +#include #include /* @@ -55,7 +56,7 @@ */ struct lprocfs_vars { const char *name; - const struct file_operations *fops; + const struct proc_ops *fops; void *data; /** /proc file mode. */ mode_t proc_mode; @@ -521,7 +522,7 @@ static inline int lprocfs_exp_cleanup(struct obd_export *exp) #endif extern struct proc_dir_entry * lprocfs_add_simple(struct proc_dir_entry *root, char *name, - void *data, const struct file_operations *fops); + void *data, const struct proc_ops *ops); extern struct proc_dir_entry * lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent, const char *format, ...); @@ -557,12 +558,10 @@ extern int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only); extern int lprocfs_obd_cleanup(struct obd_device *obd); extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name, - mode_t mode, - const struct file_operations *seq_fops, + mode_t mode, const struct proc_ops *seq_fops, void *data); extern int lprocfs_obd_seq_create(struct obd_device *obd, const char *name, - mode_t mode, - const struct file_operations *seq_fops, + mode_t mode, const struct proc_ops *seq_fops, void *data); /* Generic callbacks */ @@ -746,13 +745,13 @@ static int name##_single_open(struct inode *inode, struct file *file) \ inode->i_private ? inode->i_private : \ PDE_DATA(inode)); \ } \ -static const struct file_operations name##_fops = { \ - .owner = THIS_MODULE, \ - .open = name##_single_open, \ - .read = seq_read, \ - .write = custom_seq_write, \ - .llseek = seq_lseek, \ - .release = lprocfs_single_release, \ +static const struct proc_ops name##_fops = { \ + PROC_OWNER(THIS_MODULE) \ + .proc_open = name##_single_open, \ + .proc_read = seq_read, \ + .proc_write = custom_seq_write, \ + .proc_lseek = seq_lseek, \ + .proc_release = lprocfs_single_release, \ } #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL) @@ -793,10 +792,10 @@ static const struct file_operations name##_fops = { \ inode->i_private ? inode->i_private : \ PDE_DATA(inode)); \ } \ - static const struct file_operations name##_##type##_fops = { \ - .open = name##_##type##_open, \ - .write = name##_##type##_write, \ - .release = lprocfs_single_release, \ + static const struct proc_ops name##_##type##_fops = { \ + .proc_open = name##_##type##_open, \ + .proc_write = name##_##type##_write, \ + .proc_release = lprocfs_single_release, \ }; struct lustre_attr { diff --git a/lustre/lmv/lproc_lmv.c b/lustre/lmv/lproc_lmv.c index d313145..194bae2 100644 --- a/lustre/lmv/lproc_lmv.c +++ b/lustre/lmv/lproc_lmv.c @@ -249,12 +249,12 @@ static int lmv_target_seq_open(struct inode *inode, struct file *file) return 0; } -static const struct file_operations lmv_proc_target_fops = { - .owner = THIS_MODULE, - .open = lmv_target_seq_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, +static const struct proc_ops lmv_proc_target_fops = { + PROC_OWNER(THIS_MODULE) + .proc_open = lmv_target_seq_open, + .proc_read = seq_read, + .proc_lseek = seq_lseek, + .proc_release = seq_release, }; #endif /* CONFIG_PROC_FS */ diff --git a/lustre/lod/lod_pool.c b/lustre/lod/lod_pool.c index b23498e..a9d87e3 100644 --- a/lustre/lod/lod_pool.c +++ b/lustre/lod/lod_pool.c @@ -59,6 +59,7 @@ #include #include +#include #include #include "lod_internal.h" @@ -317,7 +318,7 @@ static int pool_proc_open(struct inode *inode, struct file *file) return rc; } -const static struct file_operations pool_proc_operations = { +const static struct proc_ops pool_proc_operations = { .open = pool_proc_open, .read = seq_read, .llseek = seq_lseek, diff --git a/lustre/lod/lproc_lod.c b/lustre/lod/lproc_lod.c index 71eea45..8cbc981 100644 --- a/lustre/lod/lproc_lod.c +++ b/lustre/lod/lproc_lod.c @@ -1015,20 +1015,20 @@ static ssize_t mdt_hash_store(struct kobject *kobj, struct attribute *attr, } LUSTRE_RW_ATTR(mdt_hash); -static const struct file_operations lod_proc_mdt_fops = { - .owner = THIS_MODULE, - .open = lod_mdts_seq_open, - .read = seq_read, - .llseek = seq_lseek, - .release = lprocfs_seq_release, +static const struct proc_ops lod_proc_mdt_fops = { + PROC_OWNER(THIS_MODULE) + .proc_open = lod_mdts_seq_open, + .proc_read = seq_read, + .proc_lseek = seq_lseek, + .proc_release = lprocfs_seq_release, }; -static const struct file_operations lod_proc_target_fops = { - .owner = THIS_MODULE, - .open = lod_osts_seq_open, - .read = seq_read, - .llseek = seq_lseek, - .release = lprocfs_seq_release, +static struct proc_ops lod_proc_target_fops = { + PROC_OWNER(THIS_MODULE) + .proc_open = lod_osts_seq_open, + .proc_read = seq_read, + .proc_lseek = seq_lseek, + .proc_release = lprocfs_seq_release, }; static struct attribute *lod_attrs[] = { diff --git a/lustre/lov/lov_pool.c b/lustre/lov/lov_pool.c index 76eb210..658ca56 100644 --- a/lustre/lov/lov_pool.c +++ b/lustre/lov/lov_pool.c @@ -42,6 +42,7 @@ #include #include +#include #include #include "lov_internal.h" @@ -223,11 +224,11 @@ static int pool_proc_open(struct inode *inode, struct file *file) return rc; } -const static struct file_operations pool_proc_operations = { - .open = pool_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, +const static struct proc_ops pool_proc_operations = { + .proc_open = pool_proc_open, + .proc_read = seq_read, + .proc_lseek = seq_lseek, + .proc_release = seq_release, }; #endif /* CONFIG_PROC_FS */ diff --git a/lustre/lov/lproc_lov.c b/lustre/lov/lproc_lov.c index 1f57285..dde1606 100644 --- a/lustre/lov/lproc_lov.c +++ b/lustre/lov/lproc_lov.c @@ -257,12 +257,12 @@ static int lov_target_seq_open(struct inode *inode, struct file *file) return 0; } -static const struct file_operations lov_proc_target_fops = { - .owner = THIS_MODULE, - .open = lov_target_seq_open, - .read = seq_read, - .llseek = seq_lseek, - .release = lprocfs_seq_release, +static const struct proc_ops lov_proc_target_fops = { + PROC_OWNER(THIS_MODULE) + .proc_open = lov_target_seq_open, + .proc_read = seq_read, + .proc_lseek = seq_lseek, + .proc_release = lprocfs_seq_release, }; #endif /* CONFIG_PROC_FS */ diff --git a/lustre/mdt/mdt_fs.c b/lustre/mdt/mdt_fs.c index 90c0269..d6f888f 100644 --- a/lustre/mdt/mdt_fs.c +++ b/lustre/mdt/mdt_fs.c @@ -36,14 +36,16 @@ #define DEBUG_SUBSYSTEM S_MDS +#include +#include #include "mdt_internal.h" -static const struct file_operations mdt_open_files_seq_fops = { - .owner = THIS_MODULE, - .open = lprocfs_mdt_open_files_seq_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, +static const struct proc_ops mdt_open_files_seq_fops = { + PROC_OWNER(THIS_MODULE) + .proc_open = lprocfs_mdt_open_files_seq_open, + .proc_read = seq_read, + .proc_lseek = seq_lseek, + .proc_release = seq_release, }; /** diff --git a/lustre/mgs/lproc_mgs.c b/lustre/mgs/lproc_mgs.c index de08cd0..91738e6 100644 --- a/lustre/mgs/lproc_mgs.c +++ b/lustre/mgs/lproc_mgs.c @@ -78,7 +78,7 @@ out: RETURN(0); } -LPROC_SEQ_FOPS_RO(mgs_fs); +LDEBUGFS_SEQ_FOPS_RO(mgs_fs); static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname, struct sptlrpc_rule_set *rset) @@ -124,7 +124,7 @@ static int mgsself_srpc_seq_show(struct seq_file *seq, void *v) return 0; } -LPROC_SEQ_FOPS_RO(mgsself_srpc); +LDEBUGFS_SEQ_FOPS_RO(mgsself_srpc); static int mgs_live_seq_show(struct seq_file *seq, void *v) { diff --git a/lustre/obdclass/lprocfs_jobstats.c b/lustre/obdclass/lprocfs_jobstats.c index 865881d..5fc89a0 100644 --- a/lustre/obdclass/lprocfs_jobstats.c +++ b/lustre/obdclass/lprocfs_jobstats.c @@ -557,13 +557,13 @@ static int lprocfs_jobstats_seq_release(struct inode *inode, struct file *file) return lprocfs_seq_release(inode, file); } -static const struct file_operations lprocfs_jobstats_seq_fops = { - .owner = THIS_MODULE, - .open = lprocfs_jobstats_seq_open, - .read = seq_read, - .write = lprocfs_jobstats_seq_write, - .llseek = seq_lseek, - .release = lprocfs_jobstats_seq_release, +static const struct proc_ops lprocfs_jobstats_seq_fops = { + PROC_OWNER(THIS_MODULE) + .proc_open = lprocfs_jobstats_seq_open, + .proc_read = seq_read, + .proc_write = lprocfs_jobstats_seq_write, + .proc_lseek = seq_lseek, + .proc_release = lprocfs_jobstats_seq_release, }; int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num, diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 8948f19..77c53bd 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -59,20 +59,29 @@ int lprocfs_seq_release(struct inode *inode, struct file *file) } EXPORT_SYMBOL(lprocfs_seq_release); +static umode_t default_mode(const struct proc_ops *ops) +{ + umode_t mode = 0; + + if (ops->proc_read) + mode = 0444; + if (ops->proc_write) + mode |= 0200; + + return mode; +} + struct proc_dir_entry * lprocfs_add_simple(struct proc_dir_entry *root, char *name, - void *data, const struct file_operations *fops) + void *data, const struct proc_ops *fops) { struct proc_dir_entry *proc; - mode_t mode = 0; + umode_t mode; if (!root || !name || !fops) return ERR_PTR(-EINVAL); - if (fops->read) - mode = 0444; - if (fops->write) - mode |= 0200; + mode = default_mode(fops); proc = proc_create_data(name, mode, root, fops, data); if (!proc) { CERROR("LprocFS: No memory to create /proc entry %s\n", @@ -139,7 +148,7 @@ void ldebugfs_add_vars(struct dentry *parent, struct ldebugfs_vars *list, } EXPORT_SYMBOL_GPL(ldebugfs_add_vars); -static const struct file_operations lprocfs_empty_ops = { }; +static const struct proc_ops lprocfs_empty_ops = { }; /** * Add /proc entries. @@ -161,16 +170,12 @@ lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list, while (list->name) { struct proc_dir_entry *proc; - mode_t mode = 0; + umode_t mode = 0; - if (list->proc_mode != 0000) { + if (list->proc_mode) mode = list->proc_mode; - } else if (list->fops) { - if (list->fops->read) - mode = 0444; - if (list->fops->write) - mode |= 0200; - } + else if (list->fops) + mode = default_mode(list->fops); proc = proc_create_data(list->name, mode, root, list->fops ?: &lprocfs_empty_ops, list->data ?: data); @@ -1414,13 +1419,13 @@ const struct file_operations ldebugfs_stats_seq_fops = { }; EXPORT_SYMBOL(ldebugfs_stats_seq_fops); -static const struct file_operations lprocfs_stats_seq_fops = { - .owner = THIS_MODULE, - .open = lprocfs_stats_seq_open, - .read = seq_read, - .write = lprocfs_stats_seq_write, - .llseek = seq_lseek, - .release = lprocfs_seq_release, +static const struct proc_ops lprocfs_stats_seq_fops = { + PROC_OWNER(THIS_MODULE) + .proc_open = lprocfs_stats_seq_open, + .proc_read = seq_read, + .proc_write = lprocfs_stats_seq_write, + .proc_lseek = seq_lseek, + .proc_release = lprocfs_seq_release, }; int lprocfs_register_stats(struct proc_dir_entry *root, const char *name, @@ -1847,14 +1852,14 @@ EXPORT_SYMBOL(lprocfs_find_named_value); int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name, mode_t mode, - const struct file_operations *seq_fops, + const struct proc_ops *seq_fops, void *data) { struct proc_dir_entry *entry; ENTRY; /* Disallow secretly (un)writable entries. */ - LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0)); + LASSERT(!seq_fops->proc_write == !(mode & 0222)); entry = proc_create_data(name, mode, parent, seq_fops, data); @@ -1868,7 +1873,7 @@ EXPORT_SYMBOL(lprocfs_seq_create); int lprocfs_obd_seq_create(struct obd_device *obd, const char *name, mode_t mode, - const struct file_operations *seq_fops, + const struct proc_ops *seq_fops, void *data) { return lprocfs_seq_create(obd->obd_proc_entry, name, diff --git a/lustre/ptlrpc/nodemap_lproc.c b/lustre/ptlrpc/nodemap_lproc.c index 2539522..408afee 100644 --- a/lustre/ptlrpc/nodemap_lproc.c +++ b/lustre/ptlrpc/nodemap_lproc.c @@ -682,21 +682,21 @@ LPROC_SEQ_FOPS_RO(nodemap_map_mode); LPROC_SEQ_FOPS_RO(nodemap_audit_mode); LPROC_SEQ_FOPS_RO(nodemap_forbid_encryption); -static const struct file_operations nodemap_ranges_fops = { +static const struct proc_ops nodemap_ranges_fops = { .open = nodemap_ranges_open, .read = seq_read, .llseek = seq_lseek, .release = single_release }; -static const struct file_operations nodemap_idmap_fops = { +static const struct proc_ops nodemap_idmap_fops = { .open = nodemap_idmap_open, .read = seq_read, .llseek = seq_lseek, .release = single_release }; -static const struct file_operations nodemap_exports_fops = { +static const struct proc_ops nodemap_exports_fops = { .open = nodemap_exports_open, .read = seq_read, .llseek = seq_lseek, diff --git a/lustre/quota/lproc_quota.c b/lustre/quota/lproc_quota.c index 010a8d2..23cc810 100644 --- a/lustre/quota/lproc_quota.c +++ b/lustre/quota/lproc_quota.c @@ -352,11 +352,11 @@ static int lprocfs_quota_seq_release(struct inode *inode, struct file *file) return seq_release(inode, file); } -const struct file_operations lprocfs_quota_seq_fops = { - .owner = THIS_MODULE, - .open = lprocfs_quota_seq_open, - .read = seq_read, - .llseek = seq_lseek, - .release = lprocfs_quota_seq_release, +const struct proc_ops lprocfs_quota_seq_fops = { + PROC_OWNER(THIS_MODULE) + .proc_open = lprocfs_quota_seq_open, + .proc_read = seq_read, + .proc_lseek = seq_lseek, + .proc_release = lprocfs_quota_seq_release, }; #endif /* CONFIG_PROC_FS */ diff --git a/lustre/quota/lquota_internal.h b/lustre/quota/lquota_internal.h index 43bcb4b..c8d69d8 100644 --- a/lustre/quota/lquota_internal.h +++ b/lustre/quota/lquota_internal.h @@ -494,7 +494,7 @@ int qmt_glb_init(void); void qmt_glb_fini(void); /* lproc_quota.c */ -extern const struct file_operations lprocfs_quota_seq_fops; +extern const struct proc_ops lprocfs_quota_seq_fops; /* qsd_lib.c */ int qsd_glb_init(void); -- 1.8.3.1