4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * API and structure definitions for params_tree.
38 * Author: LiuYing <emoly.liu@oracle.com>
40 #ifndef __PARAMS_TREE_H__
41 #define __PARAMS_TREE_H__
43 #include <libcfs/libcfs.h>
46 #if (defined(__KERNEL__) && defined(CONFIG_PROC_FS))
51 typedef struct inode cfs_inode_t;
52 typedef struct file_operations cfs_param_file_ops_t;
53 typedef struct proc_dir_entry cfs_param_dentry_t;
54 typedef struct poll_table_struct cfs_poll_table_t;
55 #define CFS_PARAM_MODULE THIS_MODULE
56 #define cfs_file_private(file) (file->private_data)
58 #ifndef HAVE_ONLY_PROCFS_SEQ
59 /* in lprocfs_stat.c, to protect the private data for proc entries */
60 extern struct rw_semaphore _lprocfs_lock;
63 int LPROCFS_ENTRY_CHECK(struct proc_dir_entry *dp)
67 spin_lock(&(dp)->pde_unload_lock);
68 if (dp->proc_fops == NULL)
70 spin_unlock(&(dp)->pde_unload_lock);
75 #define LPROCFS_SRCH_ENTRY() \
77 down_read(&_lprocfs_lock); \
80 #define LPROCFS_SRCH_EXIT() \
82 up_read(&_lprocfs_lock); \
85 #define LPROCFS_WRITE_ENTRY() \
87 down_write(&_lprocfs_lock); \
90 #define LPROCFS_WRITE_EXIT() \
92 up_write(&_lprocfs_lock); \
95 #define PDE_DATA(inode) PDE(inode)->data
97 #else /* New proc api */
99 static inline cfs_param_dentry_t* PDE(struct inode *inode)
105 int LPROCFS_ENTRY_CHECK(cfs_param_dentry_t *dp)
110 #define LPROCFS_WRITE_ENTRY() do {} while(0)
111 #define LPROCFS_WRITE_EXIT() do {} while(0)
120 unsigned int param_flags;
123 typedef struct cfs_param_inode {
127 typedef struct cfs_param_dentry {
129 } cfs_param_dentry_t;
131 typedef struct cfs_proc_inode {
132 cfs_param_dentry_t *param_pde;
133 cfs_inode_t param_inode;
136 struct seq_operations;
145 const struct seq_operations *op;
149 struct seq_operations {
150 void *(*start) (struct seq_file *m, loff_t *pos);
151 void (*stop) (struct seq_file *m, void *v);
152 void *(*next) (struct seq_file *m, void *v, loff_t *pos);
153 int (*show) (struct seq_file *m, void *v);
156 typedef void *cfs_poll_table_t;
158 typedef struct cfs_param_file_ops {
159 struct module *owner;
160 int (*open) (cfs_inode_t *, struct file *);
161 loff_t (*llseek)(struct file *, loff_t, int);
162 int (*release) (cfs_inode_t *, struct file *);
163 unsigned int (*poll) (struct file *, cfs_poll_table_t *);
164 ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
165 ssize_t (*read)(struct file *, char *, size_t, loff_t *);
166 } cfs_param_file_ops_t;
167 typedef cfs_param_file_ops_t *cfs_lproc_filep_t;
169 #define CFS_PARAM_MODULE NULL
170 #define seq_lseek NULL
172 static inline int seq_read(char *buf, size_t count, loff_t *ppos)
178 seq_open(struct file *file, const struct seq_operations *fops)
180 struct seq_file *p = file->param_private;
183 LIBCFS_ALLOC(p, sizeof(*p));
186 file->param_private = p;
188 memset(p, 0, sizeof(*p));
194 static inline cfs_proc_inode_t *FAKE_PROC_I(const cfs_inode_t *inode)
196 return container_of(inode, cfs_proc_inode_t, param_inode);
199 static inline cfs_param_dentry_t *PDE(cfs_inode_t *inode)
201 return FAKE_PROC_I(inode)->param_pde;
205 int LPROCFS_ENTRY_CHECK(cfs_param_dentry_t *dp)
209 #define LPROCFS_WRITE_ENTRY() do {} while(0)
210 #define LPROCFS_WRITE_EXIT() do {} while(0)
212 int seq_printf(struct seq_file *, const char *, ...)
213 __attribute__ ((format (printf,2,3)));
217 /* XXX: params_tree APIs */
219 #endif /* __PARAMS_TREE_H__ */