Whamcloud - gitweb
LU-3570 libcfs: accelerate crc32c with pclmulqdq
[fs/lustre-release.git] / libcfs / include / libcfs / params_tree.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * API and structure definitions for params_tree.
37  *
38  * Author: LiuYing <emoly.liu@oracle.com>
39  */
40 #ifndef __PARAMS_TREE_H__
41 #define __PARAMS_TREE_H__
42
43 #include <libcfs/libcfs.h>
44
45 #undef LPROCFS
46 #if (defined(__KERNEL__) && defined(CONFIG_PROC_FS))
47 # define LPROCFS
48 #endif
49
50 #ifdef LPROCFS
51 typedef struct file                             cfs_param_file_t;
52 typedef struct inode                            cfs_inode_t;
53 typedef struct proc_inode                       cfs_proc_inode_t;
54 typedef struct seq_file                         cfs_seq_file_t;
55 typedef struct seq_operations                   cfs_seq_ops_t;
56 typedef struct file_operations                  cfs_param_file_ops_t;
57 typedef struct proc_dir_entry                   cfs_param_dentry_t;
58 typedef struct poll_table_struct                cfs_poll_table_t;
59 #define CFS_PARAM_MODULE                        THIS_MODULE
60 #define CFS_PDE(value)                          PDE(value)
61 #define cfs_file_private(file)                  (file->private_data)
62 #define cfs_dentry_data(dentry)                 (dentry->data)
63 #define cfs_proc_inode_pde(proc_inode)          (proc_inode->pde)
64 #define cfs_proc_inode(proc_inode)              (proc_inode->vfs_inode)
65 #define cfs_seq_read_common                     seq_read
66 #define cfs_seq_lseek_common                    seq_lseek
67 #define cfs_seq_private(seq)                    (seq->private)
68 #define cfs_seq_printf(seq, format, ...)        seq_printf(seq, format,  \
69                                                            ## __VA_ARGS__)
70 #define cfs_seq_release(inode, file)            seq_release(inode, file)
71 #define cfs_seq_puts(seq, s)                    seq_puts(seq, s)
72 #define cfs_seq_putc(seq, s)                    seq_putc(seq, s)
73 #define cfs_seq_read(file, buf, count, ppos, rc) (rc = seq_read(file, buf, \
74                                                             count, ppos))
75 #define cfs_seq_open(file, ops, rc)             (rc = seq_open(file, ops))
76
77 /* in lprocfs_stat.c, to protect the private data for proc entries */
78 extern struct rw_semaphore              _lprocfs_lock;
79
80 static inline
81 int LPROCFS_ENTRY_CHECK(struct proc_dir_entry *dp)
82 {
83         int deleted = 0;
84
85         spin_lock(&(dp)->pde_unload_lock);
86         if (dp->proc_fops == NULL)
87                 deleted = 1;
88         spin_unlock(&(dp)->pde_unload_lock);
89         if (deleted)
90                 return -ENODEV;
91         return 0;
92 }
93 #define LPROCFS_SRCH_ENTRY()            \
94 do {                                    \
95         down_read(&_lprocfs_lock);      \
96 } while(0)
97
98 #define LPROCFS_SRCH_EXIT()             \
99 do {                                    \
100         up_read(&_lprocfs_lock);        \
101 } while(0)
102
103 #define LPROCFS_WRITE_ENTRY()           \
104 do {                                    \
105         down_write(&_lprocfs_lock);     \
106 } while(0)
107
108 #define LPROCFS_WRITE_EXIT()            \
109 do {                                    \
110         up_write(&_lprocfs_lock);       \
111 } while(0)
112 #else /* !LPROCFS */
113
114 typedef struct cfs_params_file {
115         void           *param_private;
116         loff_t          param_pos;
117         unsigned int    param_flags;
118 } cfs_param_file_t;
119
120 typedef struct cfs_param_inode {
121         void    *param_private;
122 } cfs_inode_t;
123
124 typedef struct cfs_param_dentry {
125         void *param_data;
126 } cfs_param_dentry_t;
127
128 typedef struct cfs_proc_inode {
129         cfs_param_dentry_t *param_pde;
130         cfs_inode_t         param_inode;
131 } cfs_proc_inode_t;
132
133 struct cfs_seq_operations;
134 typedef struct cfs_seq_file {
135         char                      *buf;
136         size_t                     size;
137         size_t                     from;
138         size_t                     count;
139         loff_t                     index;
140         loff_t                     version;
141         struct mutex                    lock;
142         struct cfs_seq_operations *op;
143         void                      *private;
144 } cfs_seq_file_t;
145
146 typedef struct cfs_seq_operations {
147         void *(*start) (cfs_seq_file_t *m, loff_t *pos);
148         void  (*stop) (cfs_seq_file_t *m, void *v);
149         void *(*next) (cfs_seq_file_t *m, void *v, loff_t *pos);
150         int   (*show) (cfs_seq_file_t *m, void *v);
151 } cfs_seq_ops_t;
152
153 typedef void *cfs_poll_table_t;
154
155 typedef struct cfs_param_file_ops{
156         struct module   *owner;
157         int (*open) (cfs_inode_t *, struct file *);
158         loff_t (*llseek)(struct file *, loff_t, int);
159         int (*release) (cfs_inode_t *, cfs_param_file_t *);
160         unsigned int (*poll) (struct file *, cfs_poll_table_t *);
161         ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
162         ssize_t (*read)(struct file *, char *, size_t, loff_t *);
163 } cfs_param_file_ops_t;
164 typedef cfs_param_file_ops_t *cfs_lproc_filep_t;
165
166 static inline cfs_proc_inode_t *FAKE_PROC_I(const cfs_inode_t *inode)
167 {
168         return container_of(inode, cfs_proc_inode_t, param_inode);
169 }
170
171 static inline cfs_param_dentry_t *FAKE_PDE(cfs_inode_t *inode)
172 {
173         return FAKE_PROC_I(inode)->param_pde;
174 }
175
176 #define CFS_PARAM_MODULE                        NULL
177 #define CFS_PDE(value)                          FAKE_PDE(value)
178 #define cfs_file_private(file)                  (file->param_private)
179 #define cfs_dentry_data(dentry)                 (dentry->param_data)
180 #define cfs_proc_inode(proc_inode)              (proc_inode->param_inode)
181 #define cfs_proc_inode_pde(proc_inode)          (proc_inode->param_pde)
182 #define cfs_seq_read_common                     NULL
183 #define cfs_seq_lseek_common                    NULL
184 #define cfs_seq_private(seq)                    (seq->private)
185 #define cfs_seq_read(file, buf, count, ppos, rc) do {} while(0)
186 #define cfs_seq_open(file, ops, rc)                     \
187 do {                                                    \
188          cfs_seq_file_t *p = cfs_file_private(file);    \
189          if (!p) {                                      \
190                 LIBCFS_ALLOC(p, sizeof(*p));            \
191                 if (!p) {                               \
192                         rc = -ENOMEM;                   \
193                         break;                          \
194                 }                                       \
195                 cfs_file_private(file) = p;             \
196         }                                               \
197         memset(p, 0, sizeof(*p));                       \
198         p->op = ops;                                    \
199         rc = 0;                                         \
200 } while(0)
201
202 static inline
203 int LPROCFS_ENTRY_CHECK(cfs_param_dentry_t *dp)
204 {
205         return 0;
206 }
207 #define LPROCFS_WRITE_ENTRY()       do {} while(0)
208 #define LPROCFS_WRITE_EXIT()        do {} while(0)
209
210 #endif /* LPROCFS */
211
212 /* XXX: params_tree APIs */
213
214 #endif  /* __PARAMS_TREE_H__ */