Whamcloud - gitweb
LU-13344 libcfs: Abstract proc_fs with proc_ops 73/37873/15
authorShaun Tancheff <shaun.tancheff@hpe.com>
Thu, 15 Apr 2021 12:07:50 +0000 (08:07 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 21 Apr 2021 03:14:57 +0000 (03:14 +0000)
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 <shaun.tancheff@hpe.com>
Change-Id: I3d8940a91b331c4f6bb31a9432194cc082c9cecd
Reviewed-on: https://review.whamcloud.com/37873
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
16 files changed:
.gitignore
libcfs/autoconf/lustre-libcfs.m4
libcfs/include/libcfs/linux/linux-fs.h
lustre/include/lprocfs_status.h
lustre/lmv/lproc_lmv.c
lustre/lod/lod_pool.c
lustre/lod/lproc_lod.c
lustre/lov/lov_pool.c
lustre/lov/lproc_lov.c
lustre/mdt/mdt_fs.c
lustre/mgs/lproc_mgs.c
lustre/obdclass/lprocfs_jobstats.c
lustre/obdclass/lprocfs_status.c
lustre/ptlrpc/nodemap_lproc.c
lustre/quota/lproc_quota.c
lustre/quota/lquota_internal.h

index 8b52cf5..d9d43e0 100644 (file)
@@ -42,6 +42,7 @@
 *.so
 *.swp
 *.unsigned
+_lpb
 00[0-9][0-9]-*.patch
 autoMakefile
 autoMakefile.in
index a4abdd2..e6bfe10 100644 (file)
@@ -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 <linux/proc_fs.h>
+
+               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
index a5beff2..78a75c7 100644 (file)
@@ -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
index c69546c..d0ab7e1 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/seq_file.h>
 
 #include <libcfs/libcfs.h>
+#include <libcfs/linux/linux-fs.h>
 #include <uapi/linux/lustre/lustre_idl.h>
 
 /*
@@ -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 {
index d313145..194bae2 100644 (file)
@@ -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 */
 
index b23498e..a9d87e3 100644 (file)
@@ -59,6 +59,7 @@
 
 #include <libcfs/libcfs.h>
 #include <libcfs/linux/linux-hash.h>
+#include <libcfs/linux/linux-fs.h>
 #include <obd.h>
 #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,
index 71eea45..8cbc981 100644 (file)
@@ -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[] = {
index 76eb210..658ca56 100644 (file)
@@ -42,6 +42,7 @@
 
 #include <libcfs/libcfs.h>
 #include <libcfs/linux/linux-hash.h>
+#include <libcfs/linux/linux-fs.h>
 
 #include <obd.h>
 #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 */
 
index 1f57285..dde1606 100644 (file)
@@ -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 */
 
index 90c0269..d6f888f 100644 (file)
 
 #define DEBUG_SUBSYSTEM S_MDS
 
+#include <linux/fs.h>
+#include <libcfs/linux/linux-fs.h>
 #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,
 };
 
 /**
index de08cd0..91738e6 100644 (file)
@@ -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)
 {
index 865881d..5fc89a0 100644 (file)
@@ -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,
index 8948f19..77c53bd 100644 (file)
@@ -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,
index 2539522..408afee 100644 (file)
@@ -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,
index 010a8d2..23cc810 100644 (file)
@@ -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 */
index 43bcb4b..c8d69d8 100644 (file)
@@ -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);