summaryrefslogtreecommitdiff
path: root/drivers/staging/lustre/include/linux/libcfs/linux/linux-prim.h
blob: a4963a8dfdd859d5b6572ed77c2e2d3fe0700b93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
 * GPL HEADER START
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 only,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License version 2 for more details (a copy is included
 * in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this program; If not, see
 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 *
 * GPL HEADER END
 */
/*
 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
 * Use is subject to license terms.
 *
 * Copyright (c) 2012, Intel Corporation.
 */
/*
 * This file is part of Lustre, http://www.lustre.org/
 * Lustre is a trademark of Sun Microsystems, Inc.
 *
 * libcfs/include/libcfs/linux/linux-prim.h
 *
 * Basic library routines.
 */

#ifndef __LIBCFS_LINUX_CFS_PRIM_H__
#define __LIBCFS_LINUX_CFS_PRIM_H__

#ifndef __LIBCFS_LIBCFS_H__
#error Do not #include this file directly. #include <linux/libcfs/libcfs.h> instead
#endif


#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/proc_fs.h>
#include <linux/mm.h>
#include <linux/timer.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/random.h>

#include <linux/miscdevice.h>
#include <linux/libcfs/linux/portals_compat25.h>
#include <asm/div64.h>

#include <linux/libcfs/linux/linux-time.h>


/*
 * CPU
 */
#ifdef for_each_possible_cpu
#define cfs_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
#elif defined(for_each_cpu)
#define cfs_for_each_possible_cpu(cpu) for_each_cpu(cpu)
#endif

#ifdef NR_CPUS
#else
#define NR_CPUS     1
#endif

/*
 * cache
 */

/*
 * IRQs
 */


/*
 * Pseudo device register
 */
typedef struct miscdevice		psdev_t;

/*
 * Sysctl register
 */
typedef struct ctl_table		ctl_table_t;
typedef struct ctl_table_header		ctl_table_header_t;

#define cfs_register_sysctl_table(t, a) register_sysctl_table(t)

#define DECLARE_PROC_HANDLER(name)		      \
static int					      \
LL_PROC_PROTO(name)				     \
{						       \
	DECLARE_LL_PROC_PPOS_DECL;		      \
							\
	return proc_call_handler(table->data, write,    \
				 ppos, buffer, lenp,    \
				 __##name);	     \
}

/*
 * Symbol register
 */
#define cfs_symbol_register(s, p)       do {} while(0)
#define cfs_symbol_unregister(s)	do {} while(0)
#define cfs_symbol_get(s)	       symbol_get(s)
#define cfs_symbol_put(s)	       symbol_put(s)

typedef struct module module_t;

/*
 * Proc file system APIs
 */
typedef struct proc_dir_entry	   proc_dir_entry_t;

/*
 * Wait Queue
 */


typedef long			    cfs_task_state_t;

#define CFS_DECL_WAITQ(wq)		DECLARE_WAIT_QUEUE_HEAD(wq)

/*
 * Task struct
 */
typedef struct task_struct	      task_t;
#define DECL_JOURNAL_DATA	   void *journal_info
#define PUSH_JOURNAL		do {    \
	journal_info = current->journal_info;   \
	current->journal_info = NULL;	   \
	} while(0)
#define POP_JOURNAL		 do {    \
	current->journal_info = journal_info;   \
	} while(0)

/* Module interfaces */
#define cfs_module(name, version, init, fini) \
	module_init(init);		    \
	module_exit(fini)

/*
 * Signal
 */

/*
 * Timer
 */
typedef struct timer_list timer_list_t;


#ifndef wait_event_timeout /* Only for RHEL3 2.4.21 kernel */
#define __wait_event_timeout(wq, condition, timeout, ret)	\
do {							     \
	int __ret = 0;					   \
	if (!(condition)) {				      \
		wait_queue_t __wait;			     \
		unsigned long expire;			    \
								 \
		init_waitqueue_entry(&__wait, current);	  \
		expire = timeout + jiffies;		      \
		add_wait_queue(&wq, &__wait);		    \
		for (;;) {				       \
			set_current_state(TASK_UNINTERRUPTIBLE); \
			if (condition)			   \
				break;			   \
			if (jiffies > expire) {		  \
				ret = jiffies - expire;	  \
				break;			   \
			}					\
			schedule_timeout(timeout);	       \
		}						\
		current->state = TASK_RUNNING;		   \
		remove_wait_queue(&wq, &__wait);		 \
	}							\
} while (0)
/*
   retval == 0; condition met; we're good.
   retval > 0; timed out.
*/
#define cfs_waitq_wait_event_timeout(wq, condition, timeout, ret)    \
do {								 \
	ret = 0;						     \
	if (!(condition))					    \
		__wait_event_timeout(wq, condition, timeout, ret);   \
} while (0)
#else
#define cfs_waitq_wait_event_timeout(wq, condition, timeout, ret)    \
	ret = wait_event_timeout(wq, condition, timeout)
#endif

#define cfs_waitq_wait_event_interruptible_timeout(wq, c, timeout, ret) \
	ret = wait_event_interruptible_timeout(wq, c, timeout)

/*
 * atomic
 */


#define cfs_atomic_add_unless(atom, a, u)    atomic_add_unless(atom, a, u)
#define cfs_atomic_cmpxchg(atom, old, nv)    atomic_cmpxchg(atom, old, nv)

/*
 * membar
 */


/*
 * interrupt
 */


/*
 * might_sleep
 */

/*
 * group_info
 */
typedef struct group_info group_info_t;


/*
 * Random bytes
 */
#endif