Whamcloud - gitweb
b=20592
[fs/lustre-release.git] / libcfs / include / libcfs / user-prim.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * libcfs/include/libcfs/user-prim.h
37  *
38  * Author: Nikita Danilov <nikita@clusterfs.com>
39  */
40
41 #ifndef __LIBCFS_USER_PRIM_H__
42 #define __LIBCFS_USER_PRIM_H__
43
44 #ifndef __LIBCFS_LIBCFS_H__
45 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
46 #endif
47
48 /* Implementations of portable APIs for liblustre */
49
50 /*
51  * liblustre is single-threaded, so most "synchronization" APIs are trivial.
52  */
53
54 #ifndef __KERNEL__
55
56 typedef struct proc_dir_entry           cfs_proc_dir_entry_t;
57
58 /*
59  * Just present a single processor until will add thread support.
60  */
61 #ifndef smp_processor_id
62 #define smp_processor_id() 0
63 #endif
64 #ifndef num_online_cpus
65 #define num_online_cpus() 1
66 #endif
67 #ifndef num_possible_cpus
68 #define num_possible_cpus() 1
69 #endif
70
71 /*
72  * Wait Queue. 
73  */
74
75 typedef struct cfs_waitlink {
76         struct list_head sleeping;
77         void *process;
78 } cfs_waitlink_t;
79
80 typedef struct cfs_waitq {
81         struct list_head sleepers;
82 } cfs_waitq_t;
83
84 /* XXX: need to replace wake_up with cfs_waitq_signal() */
85 #define wake_up(q) cfs_waitq_signal(q)
86
87 /*
88  * Task states
89  */
90 typedef long cfs_task_state_t;
91
92 #define CFS_TASK_INTERRUPTIBLE  (0)
93 #define CFS_TASK_UNINT          (1)
94 #define CFS_TASK_RUNNING        (2)
95
96
97 /* 
98  * Lproc
99  */
100 typedef int (cfs_read_proc_t)(char *page, char **start, off_t off,
101                           int count, int *eof, void *data);
102
103 struct file; /* forward ref */
104 typedef int (cfs_write_proc_t)(struct file *file, const char *buffer,
105                                unsigned long count, void *data);
106
107 /*
108  * Signal
109  */
110 typedef sigset_t                        cfs_sigset_t;
111
112 /*
113  * Timer
114  */
115
116 typedef struct {
117         struct list_head tl_list;
118         void (*function)(ulong_ptr_t unused);
119         ulong_ptr_t data;
120         long expires;
121 } cfs_timer_t;
122
123
124 #define in_interrupt()    (0)
125
126 typedef void cfs_psdev_t;
127
128 static inline int cfs_psdev_register(cfs_psdev_t *foo)
129 {
130         return 0;
131 }
132
133 static inline int cfs_psdev_deregister(cfs_psdev_t *foo)
134 {
135         return 0;
136 }
137
138 #define cfs_lock_kernel()               do {} while (0)
139 #define cfs_sigfillset(l) do {}         while (0)
140 #define cfs_recalc_sigpending(l)        do {} while (0)
141 #define cfs_kernel_thread(l,m,n)        LBUG()
142 #define cfs_kthread_run(fn,d,fmt,...)   LBUG()
143
144 #ifdef HAVE_LIBPTHREAD
145 typedef int (*cfs_thread_t)(void *);
146 int cfs_create_thread(cfs_thread_t func, void *arg);
147 #else
148 #define cfs_create_thread(l,m) LBUG()
149 #endif
150
151 uid_t cfs_curproc_uid(void);
152
153 #define LIBCFS_REALLOC(ptr, size) realloc(ptr, size)
154
155 #define cfs_online_cpus() sysconf(_SC_NPROCESSORS_ONLN)
156
157 // static inline void local_irq_save(unsigned long flag) {return;}
158 // static inline void local_irq_restore(unsigned long flag) {return;}
159
160 enum {
161         CFS_STACK_TRACE_DEPTH = 16
162 };
163
164 struct cfs_stack_trace {
165         void *frame[CFS_STACK_TRACE_DEPTH];
166 };
167
168 /*
169  * arithmetic
170  */
171 #ifndef do_div /* gcc only, platform-specific will override */
172 #define do_div(a,b)                     \
173         ({                              \
174                 unsigned long remainder;\
175                 remainder = (a) % (b);  \
176                 (a) = (a) / (b);        \
177                 (remainder);            \
178         })
179 #endif
180
181 /* utility libcfs init/fini entries */
182 #ifdef __WINNT__
183 extern int libcfs_arch_init(void);
184 extern void libcfs_arch_cleanup(void);
185 #else /* !__WINNT__ */
186 static inline int libcfs_arch_init(void) {
187         return 0;
188 }
189 static inline void libcfs_arch_cleanup(void) {
190 }
191 /* __WINNT__ */
192 #endif
193
194 /* proc interface wrappers for non-win OS */
195 #ifndef __WINNT__
196 #define cfs_proc_open   open
197 #define cfs_proc_mknod  mknod
198 #define cfs_proc_ioctl  ioctl
199 #define cfs_proc_close  close
200 #define cfs_proc_read   read
201 #define cfs_proc_write  write
202 #define cfs_proc_fopen  fopen
203 #define cfs_proc_fclose fclose
204 #define cfs_proc_fgets  fgets
205 /* !__WINNT__ */
206 #endif
207
208 /* !__KERNEL__ */
209 #endif
210
211 /* __LIBCFS_USER_PRIM_H__ */
212 #endif
213 /*
214  * Local variables:
215  * c-indentation-style: "K&R"
216  * c-basic-offset: 8
217  * tab-width: 8
218  * fill-column: 80
219  * scroll-step: 1
220  * End:
221  */