From: John L. Hammond Date: Wed, 31 Dec 2014 17:38:14 +0000 (-0600) Subject: LU-5275 lprocfs: reduce scope of params_tree.h X-Git-Tag: 2.6.93~64 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F25%2F13225%2F3;p=fs%2Flustre-release.git LU-5275 lprocfs: reduce scope of params_tree.h 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 Change-Id: Ib70575b05366565c95c1db857023c5481325308a Reviewed-on: http://review.whamcloud.com/13225 Tested-by: Jenkins Reviewed-by: James Simmons Reviewed-by: Bob Glossman Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/libcfs/include/libcfs/libcfs.h b/libcfs/include/libcfs/libcfs.h index 2fc8521..b0ce602 100644 --- a/libcfs/include/libcfs/libcfs.h +++ b/libcfs/include/libcfs/libcfs.h @@ -42,6 +42,7 @@ #ifdef __KERNEL__ # include +# include #else /* !__KERNEL__ */ # include # include @@ -281,7 +282,6 @@ void cfs_get_random_bytes(void *buf, int size); #include #include #include -#include /* container_of depends on "likely" which is defined in libcfs_private.h */ static inline void *__container_of(const void *ptr, unsigned long shift) diff --git a/libcfs/include/libcfs/params_tree.h b/libcfs/include/libcfs/params_tree.h index 92bd566..649b255 100644 --- a/libcfs/include/libcfs/params_tree.h +++ b/libcfs/include/libcfs/params_tree.h @@ -40,21 +40,23 @@ #ifndef __PARAMS_TREE_H__ #define __PARAMS_TREE_H__ -#include +#include +#include +#include +#include -#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__ */ diff --git a/lnet/klnds/gnilnd/gnilnd_proc.c b/lnet/klnds/gnilnd/gnilnd_proc.c index 6062ce5..52d0c3c 100644 --- a/lnet/klnds/gnilnd/gnilnd_proc.c +++ b/lnet/klnds/gnilnd/gnilnd_proc.c @@ -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; diff --git a/lustre/fid/lproc_fid.c b/lustre/fid/lproc_fid.c index 4338690..9561391 100644 --- a/lustre/fid/lproc_fid.c +++ b/lustre/fid/lproc_fid.c @@ -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; diff --git a/lustre/fld/lproc_fld.c b/lustre/fld/lproc_fld.c index b4e45fd..bbbecb3 100644 --- a/lustre/fld/lproc_fld.c +++ b/lustre/fld/lproc_fld.c @@ -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); diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index 41f4ad5..beb0413 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -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 = { \ diff --git a/lustre/lov/lproc_lov.c b/lustre/lov/lproc_lov.c index 77a429e..1a1de46 100644 --- a/lustre/lov/lproc_lov.c +++ b/lustre/lov/lproc_lov.c @@ -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; diff --git a/lustre/obdclass/lprocfs_jobstats.c b/lustre/obdclass/lprocfs_jobstats.c index a064916..6bb1661 100644 --- a/lustre/obdclass/lprocfs_jobstats.c +++ b/lustre/obdclass/lprocfs_jobstats.c @@ -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) diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 0f23cd9..259b79c 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -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; diff --git a/lustre/ptlrpc/lproc_ptlrpc.c b/lustre/ptlrpc/lproc_ptlrpc.c index 8f8748c..c937066 100644 --- a/lustre/ptlrpc/lproc_ptlrpc.c +++ b/lustre/ptlrpc/lproc_ptlrpc.c @@ -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; diff --git a/lustre/quota/lproc_quota.c b/lustre/quota/lproc_quota.c index 1e9f785..1102d6e 100644 --- a/lustre/quota/lproc_quota.c +++ b/lustre/quota/lproc_quota.c @@ -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)