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#ifndef __LIBCFS_LIBCFS_H__
38#define __LIBCFS_LIBCFS_H__
39
40#if !__GNUC__
41#define __attribute__(x)
42#endif
43
44#include <linux/libcfs/linux/libcfs.h>
45
46#include "curproc.h"
47
48#ifndef offsetof
49# define offsetof(typ,memb) ((long)(long_ptr_t)((char *)&(((typ *)0)->memb)))
50#endif
51
52#ifndef ARRAY_SIZE
53#define ARRAY_SIZE(a) ((sizeof (a)) / (sizeof ((a)[0])))
54#endif
55
56#if !defined(swap)
57#define swap(x,y) do { typeof(x) z = x; x = y; y = z; } while (0)
58#endif
59
60#if !defined(container_of)
61
62
63#define container_of(ptr, type, member) \
64 ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
65#endif
66
67static inline int __is_po2(unsigned long long val)
68{
69 return !(val & (val - 1));
70}
71
72#define IS_PO2(val) __is_po2((unsigned long long)(val))
73
74#define LOWEST_BIT_SET(x) ((x) & ~((x) - 1))
75
76
77
78
79
80#define LERRCHKSUM(hexnum) (((hexnum) & 0xf) ^ ((hexnum) >> 4 & 0xf) ^ \
81 ((hexnum) >> 8 & 0xf))
82
83
84
85
86
87
88#if defined(NULL)
89#undef NULL
90#endif
91
92#define NULL ((void *)0)
93
94#define LUSTRE_SRV_LNET_PID LUSTRE_LNET_PID
95
96
97#include <linux/list.h>
98
99#ifndef cfs_for_each_possible_cpu
100# error cfs_for_each_possible_cpu is not supported by kernel!
101#endif
102
103
104int libcfs_ipif_query(char *name, int *up, __u32 *ip, __u32 *mask);
105int libcfs_ipif_enumerate(char ***names);
106void libcfs_ipif_free_enumeration(char **names, int n);
107int libcfs_sock_listen(socket_t **sockp, __u32 ip, int port, int backlog);
108int libcfs_sock_accept(socket_t **newsockp, socket_t *sock);
109void libcfs_sock_abort_accept(socket_t *sock);
110int libcfs_sock_connect(socket_t **sockp, int *fatal,
111 __u32 local_ip, int local_port,
112 __u32 peer_ip, int peer_port);
113int libcfs_sock_setbuf(socket_t *socket, int txbufsize, int rxbufsize);
114int libcfs_sock_getbuf(socket_t *socket, int *txbufsize, int *rxbufsize);
115int libcfs_sock_getaddr(socket_t *socket, int remote, __u32 *ip, int *port);
116int libcfs_sock_write(socket_t *sock, void *buffer, int nob, int timeout);
117int libcfs_sock_read(socket_t *sock, void *buffer, int nob, int timeout);
118void libcfs_sock_release(socket_t *sock);
119
120
121struct lc_watchdog;
122
123
124
125struct lc_watchdog *lc_watchdog_add(int time,
126 void (*cb)(pid_t pid, void *),
127 void *data);
128
129
130void lc_watchdog_touch(struct lc_watchdog *lcw, int timeout);
131#define CFS_GET_TIMEOUT(svc) (max_t(int, obd_timeout, \
132 AT_OFF ? 0 : at_get(&svc->srv_at_estimate)) * \
133 svc->srv_watchdog_factor)
134
135
136void lc_watchdog_disable(struct lc_watchdog *lcw);
137
138
139void lc_watchdog_delete(struct lc_watchdog *lcw);
140
141
142void lc_watchdog_dumplog(pid_t pid, void *data);
143
144
145
146#define LNET_ACCEPTOR_MIN_RESERVED_PORT 512
147#define LNET_ACCEPTOR_MAX_RESERVED_PORT 1023
148
149
150
151
152
153
154
155
156
157
158
159
160struct cfs_psdev_file {
161 unsigned long off;
162 void *private_data;
163 unsigned long reserved1;
164 unsigned long reserved2;
165};
166
167struct cfs_psdev_ops {
168 int (*p_open)(unsigned long, void *);
169 int (*p_close)(unsigned long, void *);
170 int (*p_read)(struct cfs_psdev_file *, char *, unsigned long);
171 int (*p_write)(struct cfs_psdev_file *, char *, unsigned long);
172 int (*p_ioctl)(struct cfs_psdev_file *, unsigned long, void *);
173};
174
175
176
177
178
179void cfs_enter_debugger(void);
180
181
182
183
184int unshare_fs_struct(void);
185sigset_t cfs_get_blocked_sigs(void);
186sigset_t cfs_block_allsigs(void);
187sigset_t cfs_block_sigs(unsigned long sigs);
188sigset_t cfs_block_sigsinv(unsigned long sigs);
189void cfs_restore_sigs(sigset_t);
190int cfs_signal_pending(void);
191void cfs_clear_sigpending(void);
192
193
194
195
196
197
198unsigned int cfs_rand(void);
199
200void cfs_srand(unsigned int, unsigned int);
201void cfs_get_random_bytes(void *buf, int size);
202
203#include <linux/libcfs/libcfs_debug.h>
204#include <linux/libcfs/libcfs_cpu.h>
205#include <linux/libcfs/libcfs_private.h>
206#include <linux/libcfs/libcfs_ioctl.h>
207#include <linux/libcfs/libcfs_prim.h>
208#include <linux/libcfs/libcfs_time.h>
209#include <linux/libcfs/libcfs_string.h>
210#include <linux/libcfs/libcfs_kernelcomm.h>
211#include <linux/libcfs/libcfs_workitem.h>
212#include <linux/libcfs/libcfs_hash.h>
213#include <linux/libcfs/libcfs_heap.h>
214#include <linux/libcfs/libcfs_fail.h>
215#include <linux/libcfs/params_tree.h>
216#include <linux/libcfs/libcfs_crypto.h>
217
218
219static inline void *__container_of(void *ptr, unsigned long shift)
220{
221 if (unlikely(IS_ERR(ptr) || ptr == NULL))
222 return ptr;
223 else
224 return (char *)ptr - shift;
225}
226
227#define container_of0(ptr, type, member) \
228 ((type *)__container_of((void *)(ptr), offsetof(type, member)))
229
230#define SET_BUT_UNUSED(a) do { } while(sizeof(a) - sizeof(a))
231
232#define _LIBCFS_H
233
234#endif
235