#ifdef __KERNEL__
# include <libcfs/linux/libcfs.h>
+# include <libcfs/params_tree.h>
#else /* !__KERNEL__ */
# include <assert.h>
# include <ctype.h>
#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)
#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);
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;
}
#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__ */
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;
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;
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;
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;
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);
#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 = { \
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;
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)
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;
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 = {
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;
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;
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)