Whamcloud - gitweb
LU-13344 libcfs: Abstract proc_fs with proc_ops
authorShaun Tancheff <shaun.tancheff@hpe.com>
Tue, 11 May 2021 04:22:12 +0000 (21:22 -0700)
committerLi Xi <lixi@ddn.com>
Tue, 18 May 2021 01:46:51 +0000 (01:46 +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.

Lustre-change: https://review.whamcloud.com/37873
Lustre-commit: 13cd0f9f667c6e138a8cb235d4920f8b749cb154

Test-Parameters: trivial
HPE-bug-id: LUS-8589
Signed-off-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Change-Id: I3d8940a91b331c4f6bb31a9432194cc082c9cecd
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/43642
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Li Xi <lixi@ddn.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 529b534..2d8e72b 100644 (file)
@@ -1290,6 +1290,32 @@ EXTRA_KCFLAGS="$tmp_flags"
 ]) # LIBCFS_CACHE_DETAIL_WRITERS
 
 #
+# 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_HAVE_NR_UNSTABLE_NFS
 #
 # kernel v5.8-rc1~201^2~75
@@ -1312,8 +1338,17 @@ nr_unstable_nfs_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 13c2e50..6cb0f29 100644 (file)
@@ -60,4 +60,21 @@ static inline struct dentry *file_dentry(const struct file *file)
 #define DTTOIF(dirtype)                ((dirtype) << IFSHIFT)
 #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 2d23c81..c0e6f67 100644 (file)
@@ -47,6 +47,7 @@
 #include <linux/seq_file.h>
 
 #include <libcfs/libcfs.h>
+#include <libcfs/linux/linux-fs.h>
 #include <uapi/linux/lustre/lustre_idl.h>
 
 /*
@@ -56,7 +57,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;
@@ -522,7 +523,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, ...);
@@ -558,12 +559,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 */
@@ -739,13 +738,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)
@@ -786,10 +785,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 6e0e7cc..a254966 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 c69b07c..741842c 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 1ca3f5c..91d9672 100644 (file)
@@ -1023,20 +1023,20 @@ static struct lprocfs_vars lprocfs_lod_obd_vars[] = {
        { NULL }
 };
 
-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 c5556c9..abdd5fc 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 1da6945..e63ee71 100644 (file)
@@ -277,12 +277,12 @@ struct lprocfs_vars lprocfs_lov_obd_vars[] = {
        { NULL }
 };
 
-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 ec6e7ca..4e678b7 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);
@@ -1418,13 +1423,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,
@@ -1853,14 +1858,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);
 
@@ -1874,7 +1879,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 87feff4..0137054 100644 (file)
@@ -684,21 +684,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 de78fd4..c95fb9e 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 2629882..58c960e 100644 (file)
@@ -493,7 +493,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);