Whamcloud - gitweb
LU-5275 lprocfs: reduce scope of params_tree.h 25/13225/3
authorJohn L. Hammond <john.hammond@intel.com>
Wed, 31 Dec 2014 17:38:14 +0000 (11:38 -0600)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 10 Jan 2015 04:39:47 +0000 (04:39 +0000)
Only include libcfs/params_tree.h for kernel builds. Eliminate the
include cycle between libcfs.h and params_tree.h. Remove nonsensical
stub definitions for struct file, struct inode, and others. Remove
several uses of PDE() by modifying LPROCFS_ENTRY_CHECK() to accept a
struct inode * rather than a struct proc_dir_entry *. Correct several
nop uses of LPROCFS_ENTRY_CHECK().

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: Ib70575b05366565c95c1db857023c5481325308a
Reviewed-on: http://review.whamcloud.com/13225
Tested-by: Jenkins
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
libcfs/include/libcfs/libcfs.h
libcfs/include/libcfs/params_tree.h
lnet/klnds/gnilnd/gnilnd_proc.c
lustre/fid/lproc_fid.c
lustre/fld/lproc_fld.c
lustre/include/lprocfs_status.h
lustre/lov/lproc_lov.c
lustre/obdclass/lprocfs_jobstats.c
lustre/obdclass/lprocfs_status.c
lustre/ptlrpc/lproc_ptlrpc.c
lustre/quota/lproc_quota.c

index 2fc8521..b0ce602 100644 (file)
@@ -42,6 +42,7 @@
 
 #ifdef __KERNEL__
 # include <libcfs/linux/libcfs.h>
+# include <libcfs/params_tree.h>
 #else /* !__KERNEL__ */
 # include <assert.h>
 # include <ctype.h>
@@ -281,7 +282,6 @@ void cfs_get_random_bytes(void *buf, int size);
 #include <libcfs/libcfs_hash.h>
 #include <libcfs/libcfs_heap.h>
 #include <libcfs/libcfs_fail.h>
-#include <libcfs/params_tree.h>
 
 /* container_of depends on "likely" which is defined in libcfs_private.h */
 static inline void *__container_of(const void *ptr, unsigned long shift)
index 92bd566..649b255 100644 (file)
 #ifndef __PARAMS_TREE_H__
 #define __PARAMS_TREE_H__
 
-#include <libcfs/libcfs.h>
+#include <linux/fs.h>
+#include <linux/proc_fs.h>
+#include <linux/rwsem.h>
+#include <linux/spinlock.h>
 
-#undef LPROCFS
-#if (defined(__KERNEL__) && defined(CONFIG_PROC_FS))
+#ifdef CONFIG_PROC_FS
 # define LPROCFS
-#endif
+#endif /* CONFIG_PROC_FS */
 
 #ifdef LPROCFS
-#ifndef HAVE_ONLY_PROCFS_SEQ
+# ifndef HAVE_ONLY_PROCFS_SEQ
 /* in lprocfs_stat.c, to protect the private data for proc entries */
 extern struct rw_semaphore             _lprocfs_lock;
 
-static inline
-int LPROCFS_ENTRY_CHECK(struct proc_dir_entry *dp)
+static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
 {
+       struct proc_dir_entry *dp = PDE(inode);
        int deleted = 0;
 
        spin_lock(&(dp)->pde_unload_lock);
@@ -65,37 +67,32 @@ int LPROCFS_ENTRY_CHECK(struct proc_dir_entry *dp)
                return -ENODEV;
        return 0;
 }
-#define LPROCFS_SRCH_ENTRY()            \
-do {                                    \
-        down_read(&_lprocfs_lock);      \
-} while(0)
 
-#define LPROCFS_SRCH_EXIT()             \
-do {                                    \
-        up_read(&_lprocfs_lock);        \
-} while(0)
+#  define LPROCFS_SRCH_ENTRY()                 \
+       do {                                    \
+               down_read(&_lprocfs_lock);      \
+       } while (0)
 
-#define LPROCFS_WRITE_ENTRY()          \
-do {                                   \
-       down_write(&_lprocfs_lock);     \
-} while(0)
+#  define LPROCFS_SRCH_EXIT()                  \
+       do {                                    \
+               up_read(&_lprocfs_lock);        \
+       } while (0)
 
-#define LPROCFS_WRITE_EXIT()           \
-do {                                   \
-       up_write(&_lprocfs_lock);       \
-} while(0)
+#  define LPROCFS_WRITE_ENTRY()                        \
+       do {                                    \
+               down_write(&_lprocfs_lock);     \
+       } while (0)
 
-#define PDE_DATA(inode)                PDE(inode)->data
+#  define LPROCFS_WRITE_EXIT()                 \
+       do {                                    \
+               up_write(&_lprocfs_lock);       \
+       } while (0)
 
-#else /* New proc api */
+#  define PDE_DATA(inode)      (PDE(inode)->data)
 
-static inline struct proc_dir_entry *PDE(struct inode *inode)
-{
-       return NULL;
-}
+# else /* HAVE_ONLY_PROCFS_SEQ */
 
-static inline
-int LPROCFS_ENTRY_CHECK(struct proc_dir_entry *dp)
+static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
 {
        return 0;
 }
@@ -103,100 +100,6 @@ int LPROCFS_ENTRY_CHECK(struct proc_dir_entry *dp)
 #define LPROCFS_WRITE_ENTRY() do {} while(0)
 #define LPROCFS_WRITE_EXIT()  do {} while(0)
 
-#endif
-
-#else /* !LPROCFS */
-
-struct file {
-       void            *param_private;
-       loff_t          param_pos;
-       unsigned int    param_flags;
-};
-
-struct inode {
-       void            *param_private;
-};
-
-struct poll_table_struct {
-       void            *pad;
-};
-
-struct proc_dir_entry {
-       void            *param_data;
-};
-
-struct proc_inode {
-       struct proc_dir_entry   *param_pde;
-       struct inode            param_inode;
-};
-
-struct seq_operations;
-struct seq_file {
-       char                            *buf;
-       size_t                          size;
-       size_t                          from;
-       size_t                          count;
-       loff_t                          index;
-       loff_t                          version;
-       struct mutex                    lock;
-       const struct seq_operations     *op;
-       void                            *private;
-};
-
-struct seq_operations {
-       void *(*start) (struct seq_file *m, loff_t *pos);
-       void  (*stop) (struct seq_file *m, void *v);
-       void *(*next) (struct seq_file *m, void *v, loff_t *pos);
-       int   (*show) (struct seq_file *m, void *v);
-};
-
-#define seq_lseek      NULL
-
-static inline int seq_read(char *buf, size_t count, loff_t *ppos)
-{
-       return 0;
-}
-
-static inline int
-seq_open(struct file *file, const struct seq_operations *fops)
-{
-       struct seq_file *p = file->param_private;
-
-       if (p == NULL) {
-               LIBCFS_ALLOC(p, sizeof(*p));
-               if (p == NULL)
-                       return -ENOMEM;
-               file->param_private = p;
-       } else {
-               memset(p, 0, sizeof(*p));
-       }
-       p->op = fops;
-       return 0;
-}
-
-static inline struct proc_inode *FAKE_PROC_I(const struct inode *inode)
-{
-       return container_of(inode, struct proc_inode, param_inode);
-}
-
-static inline struct proc_dir_entry *PDE(struct inode *inode)
-{
-       return FAKE_PROC_I(inode)->param_pde;
-}
-
-static inline
-int LPROCFS_ENTRY_CHECK(struct proc_dir_entry *dp)
-{
-       return 0;
-}
-#define LPROCFS_WRITE_ENTRY()       do {} while(0)
-#define LPROCFS_WRITE_EXIT()        do {} while(0)
-
-int seq_printf(struct seq_file *, const char *, ...)
-       __attribute__ ((format (printf,2,3)));
-
+# endif /* !HAVE_ONLY_PROCFS_SEQ */
 #endif /* LPROCFS */
-
-/* XXX: params_tree APIs */
-
 #endif  /* __PARAMS_TREE_H__ */
index 6062ce5..52d0c3c 100644 (file)
@@ -691,14 +691,13 @@ static struct seq_operations kgn_smsg_sops = {
 static int
 kgnilnd_smsg_seq_open(struct inode *inode, struct file *file)
 {
-       struct proc_dir_entry *dp = PDE(inode);
        struct seq_file       *sf;
        int                    rc;
 
        rc = seq_open(file, &kgn_smsg_sops);
        if (rc == 0) {
                sf = file->private_data;
-               sf->private = dp->data;
+               sf->private = PDE_DATA(inode);
        }
 
        return rc;
@@ -1032,14 +1031,13 @@ kgnilnd_proc_peer_conns_read(char *page, char **start, off_t off,
 static int
 kgnilnd_conn_seq_open(struct inode *inode, struct file *file)
 {
-       struct proc_dir_entry *dp = PDE(inode);
        struct seq_file       *sf;
        int                    rc;
 
        rc = seq_open(file, &kgn_conn_sops);
        if (rc == 0) {
                sf = file->private_data;
-               sf->private = dp->data;
+               sf->private = PDE_DATA(inode);
        }
 
        return rc;
@@ -1256,14 +1254,13 @@ static struct seq_operations kgn_peer_sops = {
 static int
 kgnilnd_peer_seq_open(struct inode *inode, struct file *file)
 {
-       struct proc_dir_entry *dp = PDE(inode);
        struct seq_file       *sf;
        int                    rc;
 
        rc = seq_open(file, &kgn_peer_sops);
        if (rc == 0) {
                sf = file->private_data;
-               sf->private = dp->data;
+               sf->private = PDE_DATA(inode);
        }
 
        return rc;
index 4338690..9561391 100644 (file)
@@ -361,7 +361,10 @@ static int fldb_seq_open(struct inode *inode, struct file *file)
        fld = ss->lss_site->ss_server_fld;
        LASSERT(fld != NULL);
 
-       LPROCFS_ENTRY_CHECK(PDE(inode));
+       rc = LPROCFS_ENTRY_CHECK(inode);
+       if (rc < 0)
+               return rc;
+
        rc = seq_open(file, &fldb_sops);
        if (rc)
                return rc;
index b4e45fd..bbbecb3 100644 (file)
@@ -279,7 +279,10 @@ static int fldb_seq_open(struct inode *inode, struct file *file)
        int                     env_init = 0;
        int                     rc;
 
-       LPROCFS_ENTRY_CHECK(PDE(inode));
+       rc = LPROCFS_ENTRY_CHECK(inode);
+       if (rc < 0)
+               return rc;
+
        rc = seq_open(file, &fldb_sops);
        if (rc)
                GOTO(out, rc);
index 41f4ad5..beb0413 100644 (file)
@@ -782,7 +782,12 @@ extern int lprocfs_seq_release(struct inode *, struct file *);
 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                       \
 static int name##_single_open(struct inode *inode, struct file *file)  \
 {                                                                      \
-       LPROCFS_ENTRY_CHECK(PDE(inode));                                \
+       int rc;                                                         \
+                                                                       \
+       rc = LPROCFS_ENTRY_CHECK(inode);                                \
+       if (rc < 0)                                                     \
+               return rc;                                              \
+                                                                       \
        return single_open(file, name##_seq_show, PDE_DATA(inode));     \
 }                                                                      \
 static const struct file_operations name##_fops = {                    \
index 77a429e..1a1de46 100644 (file)
@@ -248,7 +248,10 @@ static int lov_target_seq_open(struct inode *inode, struct file *file)
        struct seq_file *seq;
        int rc;
 
-       LPROCFS_ENTRY_CHECK(PDE(inode));
+       rc = LPROCFS_ENTRY_CHECK(inode);
+       if (rc < 0)
+               return rc;
+
        rc = seq_open(file, &lov_tgt_sops);
        if (rc)
                return rc;
index a064916..6bb1661 100644 (file)
@@ -416,8 +416,9 @@ static int lprocfs_jobstats_seq_open(struct inode *inode, struct file *file)
        struct seq_file *seq;
        int rc;
 
-       if (LPROCFS_ENTRY_CHECK(PDE(inode)))
-               return -ENOENT;
+       rc = LPROCFS_ENTRY_CHECK(inode);
+       if (rc < 0)
+               return rc;
 
        rc = seq_open(file, &lprocfs_jobstats_seq_sops);
        if (rc)
index 0f23cd9..259b79c 100644 (file)
@@ -124,26 +124,29 @@ static const struct file_operations lprocfs_generic_fops = { };
 ssize_t
 lprocfs_fops_read(struct file *f, char __user *buf, size_t size, loff_t *ppos)
 {
-        struct proc_dir_entry *dp = PDE(f->f_dentry->d_inode);
-        char *page, *start = NULL;
-        int rc = 0, eof = 1, count;
+       struct inode *inode = f->f_dentry->d_inode;
+       struct proc_dir_entry *dp = PDE(inode);
+       char *page, *start = NULL;
+       int rc, eof = 1, count;
 
        if (*ppos >= PAGE_CACHE_SIZE)
-                return 0;
+               return 0;
 
-        page = (char *)__get_free_page(GFP_KERNEL);
-        if (page == NULL)
-                return -ENOMEM;
+       page = (char *)__get_free_page(GFP_KERNEL);
+       if (page == NULL)
+               return -ENOMEM;
 
-       if (LPROCFS_ENTRY_CHECK(dp)) {
-                rc = -ENOENT;
-                goto out;
-        }
+       rc = LPROCFS_ENTRY_CHECK(inode);
+       if (rc < 0)
+               goto out;
 
-        OBD_FAIL_TIMEOUT(OBD_FAIL_LPROC_REMOVE, 10);
-        if (dp->read_proc)
+       OBD_FAIL_TIMEOUT(OBD_FAIL_LPROC_REMOVE, 10);
+       if (dp->read_proc != NULL)
                rc = dp->read_proc(page, &start, *ppos, PAGE_CACHE_SIZE,
-                                   &eof, dp->data);
+                                  &eof, dp->data);
+       else
+               rc = 0;
+
         if (rc <= 0)
                 goto out;
 
@@ -177,14 +180,20 @@ ssize_t
 lprocfs_fops_write(struct file *f, const char __user *buf, size_t size,
                   loff_t *ppos)
 {
-        struct proc_dir_entry *dp = PDE(f->f_dentry->d_inode);
-        int rc = -EIO;
+       struct inode *inode = f->f_dentry->d_inode;
+       struct proc_dir_entry *dp = PDE(inode);
+       int rc;
 
-       if (LPROCFS_ENTRY_CHECK(dp))
-                return -ENOENT;
-        if (dp->write_proc)
-                rc = dp->write_proc(f, buf, size, dp->data);
-        return rc;
+       rc = LPROCFS_ENTRY_CHECK(inode);
+       if (rc < 0)
+               return rc;
+
+       if (dp->write_proc != NULL)
+               rc = dp->write_proc(f, buf, size, dp->data);
+       else
+               rc = -EIO;
+
+       return rc;
 }
 
 static struct file_operations lprocfs_generic_fops = {
@@ -1478,10 +1487,10 @@ static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
        struct seq_file *seq;
        int rc;
 
-#ifndef HAVE_ONLY_PROCFS_SEQ
-       if (LPROCFS_ENTRY_CHECK(PDE(inode)))
-               return -ENOENT;
-#endif
+       rc = LPROCFS_ENTRY_CHECK(inode);
+       if (rc < 0)
+               return rc;
+
        rc = seq_open(file, &lprocfs_stats_seq_sops);
        if (rc)
                return rc;
index 8f8748c..c937066 100644 (file)
@@ -980,7 +980,10 @@ ptlrpc_lprocfs_svc_req_history_open(struct inode *inode, struct file *file)
        struct seq_file *seqf;
        int             rc;
 
-       LPROCFS_ENTRY_CHECK(PDE(inode));
+       rc = LPROCFS_ENTRY_CHECK(inode);
+       if (rc < 0)
+               return rc;
+
        rc = seq_open(file, &sops);
        if (rc)
                return rc;
index 1e9f785..1102d6e 100644 (file)
@@ -279,10 +279,9 @@ static int lprocfs_quota_seq_open(struct inode *inode, struct file *file)
                goto out_lqp;
        }
 
-       if (LPROCFS_ENTRY_CHECK(PDE(inode))) {
-               rc = -ENOENT;
+       rc = LPROCFS_ENTRY_CHECK(inode);
+       if (rc < 0)
                goto out_env;
-       }
 
        rc = seq_open(file, &lprocfs_quota_seq_sops);
        if (rc)