1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
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__
44 # define EXPORT_SYMTAB
47 #include <libcfs/libcfs.h>
50 #if (defined(__KERNEL__) && defined(CONFIG_PROC_FS))
55 typedef struct file cfs_param_file_t;
56 typedef struct inode cfs_inode_t;
57 typedef struct proc_inode cfs_proc_inode_t;
58 typedef struct seq_file cfs_seq_file_t;
59 typedef struct seq_operations cfs_seq_ops_t;
60 typedef struct file_operations cfs_param_file_ops_t;
61 typedef cfs_module_t *cfs_param_module_t;
62 typedef struct proc_dir_entry cfs_param_dentry_t;
63 typedef struct poll_table_struct cfs_poll_table_t;
64 #define CFS_PARAM_MODULE THIS_MODULE
65 #define CFS_PDE(value) PDE(value)
66 #define cfs_file_private(file) (file->private_data)
67 #define cfs_dentry_data(dentry) (dentry->data)
68 #define cfs_proc_inode_pde(proc_inode) (proc_inode->pde)
69 #define cfs_proc_inode(proc_inode) (proc_inode->vfs_inode)
70 #define cfs_seq_read_common seq_read
71 #define cfs_seq_lseek_common seq_lseek
72 #define cfs_seq_private(seq) (seq->private)
73 #define cfs_seq_printf(seq, format, ...) seq_printf(seq, format, \
75 #define cfs_seq_release(inode, file) seq_release(inode, file)
76 #define cfs_seq_puts(seq, s) seq_puts(seq, s)
77 #define cfs_seq_putc(seq, s) seq_putc(seq, s)
78 #define cfs_seq_read(file, buf, count, ppos, rc) (rc = seq_read(file, buf, \
80 #define cfs_seq_open(file, ops, rc) (rc = seq_open(file, ops))
82 /* in lprocfs_stat.c, to protect the private data for proc entries */
83 extern cfs_rw_semaphore_t _lprocfs_lock;
84 #define LPROCFS_ENTRY() \
86 cfs_down_read(&_lprocfs_lock); \
88 #define LPROCFS_EXIT() \
90 cfs_up_read(&_lprocfs_lock); \
93 #ifdef HAVE_PROCFS_DELETED
95 int LPROCFS_ENTRY_AND_CHECK(struct proc_dir_entry *dp)
104 #else /* !HAVE_PROCFS_DELETED*/
106 int LPROCFS_ENTRY_AND_CHECK(struct proc_dir_entry *dp)
111 #endif /* HAVE_PROCFS_DELETED */
113 #define LPROCFS_WRITE_ENTRY() \
115 cfs_down_write(&_lprocfs_lock); \
117 #define LPROCFS_WRITE_EXIT() \
119 cfs_up_write(&_lprocfs_lock); \
124 typedef struct cfs_params_file {
127 unsigned int param_flags;
130 typedef struct cfs_param_inode {
134 typedef struct cfs_param_dentry {
136 } cfs_param_dentry_t;
138 typedef struct cfs_proc_inode {
139 cfs_param_dentry_t *param_pde;
140 cfs_inode_t param_inode;
143 struct cfs_seq_operations;
144 typedef struct cfs_seq_file {
152 struct cfs_seq_operations *op;
156 typedef struct cfs_seq_operations {
157 void *(*start) (cfs_seq_file_t *m, loff_t *pos);
158 void (*stop) (cfs_seq_file_t *m, void *v);
159 void *(*next) (cfs_seq_file_t *m, void *v, loff_t *pos);
160 int (*show) (cfs_seq_file_t *m, void *v);
163 typedef void *cfs_param_module_t;
164 typedef void *cfs_poll_table_t;
166 typedef struct cfs_param_file_ops {
167 cfs_param_module_t owner;
168 int (*open) (cfs_inode_t *, cfs_file_t *);
169 loff_t (*llseek)(cfs_file_t *, loff_t, int);
170 int (*release) (cfs_inode_t *, cfs_param_file_t *);
171 unsigned int (*poll) (cfs_file_t *, cfs_poll_table_t *);
172 ssize_t (*write) (cfs_file_t *, const char *, size_t, loff_t *);
173 ssize_t (*read)(cfs_file_t *, char *, size_t, loff_t *);
174 } cfs_param_file_ops_t;
175 typedef cfs_param_file_ops_t *cfs_lproc_filep_t;
177 static inline cfs_proc_inode_t *FAKE_PROC_I(const cfs_inode_t *inode)
179 return container_of(inode, cfs_proc_inode_t, param_inode);
182 static inline cfs_param_dentry_t *FAKE_PDE(cfs_inode_t *inode)
184 return FAKE_PROC_I(inode)->param_pde;
187 #define CFS_PARAM_MODULE NULL
188 #define CFS_PDE(value) FAKE_PDE(value)
189 #define cfs_file_private(file) (file->param_private)
190 #define cfs_dentry_data(dentry) (dentry->param_data)
191 #define cfs_proc_inode(proc_inode) (proc_inode->param_inode)
192 #define cfs_proc_inode_pde(proc_inode) (proc_inode->param_pde)
193 #define cfs_seq_read_common NULL
194 #define cfs_seq_lseek_common NULL
195 #define cfs_seq_private(seq) (seq->private)
196 #define cfs_seq_read(file, buf, count, ppos, rc) do {} while(0)
197 #define cfs_seq_open(file, ops, rc) \
199 cfs_seq_file_t *p = cfs_file_private(file); \
201 LIBCFS_ALLOC(p, sizeof(*p)); \
206 cfs_file_private(file) = p; \
208 memset(p, 0, sizeof(*p)); \
213 #define LPROCFS_ENTRY() do {} while(0)
214 #define LPROCFS_EXIT() do {} while(0)
216 int LPROCFS_ENTRY_AND_CHECK(cfs_param_dentry_t *dp)
221 #define LPROCFS_WRITE_ENTRY() do {} while(0)
222 #define LPROCFS_WRITE_EXIT() do {} while(0)
226 /* XXX: params_tree APIs */
228 #endif /* __PARAMS_TREE_H__ */