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.h"
45#include <linux/gfp.h>
46
47#include "curproc.h"
48
49#ifndef offsetof
50# define offsetof(typ, memb) ((long)(long_ptr_t)((char *)&(((typ *)0)->memb)))
51#endif
52
53#ifndef ARRAY_SIZE
54#define ARRAY_SIZE(a) ((sizeof(a)) / (sizeof((a)[0])))
55#endif
56
57#if !defined(swap)
58#define swap(x, y) do { typeof(x) z = x; x = y; y = z; } while (0)
59#endif
60
61#if !defined(container_of)
62
63
64#define container_of(ptr, type, member) \
65 ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
66#endif
67
68static inline int __is_po2(unsigned long long val)
69{
70 return !(val & (val - 1));
71}
72
73#define IS_PO2(val) __is_po2((unsigned long long)(val))
74
75#define LOWEST_BIT_SET(x) ((x) & ~((x) - 1))
76
77
78
79
80
81#define LERRCHKSUM(hexnum) (((hexnum) & 0xf) ^ ((hexnum) >> 4 & 0xf) ^ \
82 ((hexnum) >> 8 & 0xf))
83
84#define LUSTRE_SRV_LNET_PID LUSTRE_LNET_PID
85
86#include <linux/list.h>
87
88int libcfs_arch_init(void);
89void libcfs_arch_cleanup(void);
90
91
92int libcfs_ipif_query(char *name, int *up, __u32 *ip, __u32 *mask);
93int libcfs_ipif_enumerate(char ***names);
94void libcfs_ipif_free_enumeration(char **names, int n);
95int libcfs_sock_listen(struct socket **sockp, __u32 ip, int port, int backlog);
96int libcfs_sock_accept(struct socket **newsockp, struct socket *sock);
97void libcfs_sock_abort_accept(struct socket *sock);
98int libcfs_sock_connect(struct socket **sockp, int *fatal,
99 __u32 local_ip, int local_port,
100 __u32 peer_ip, int peer_port);
101int libcfs_sock_setbuf(struct socket *socket, int txbufsize, int rxbufsize);
102int libcfs_sock_getbuf(struct socket *socket, int *txbufsize, int *rxbufsize);
103int libcfs_sock_getaddr(struct socket *socket, int remote, __u32 *ip, int *port);
104int libcfs_sock_write(struct socket *sock, void *buffer, int nob, int timeout);
105int libcfs_sock_read(struct socket *sock, void *buffer, int nob, int timeout);
106void libcfs_sock_release(struct socket *sock);
107
108
109#define LNET_ACCEPTOR_MIN_RESERVED_PORT 512
110#define LNET_ACCEPTOR_MAX_RESERVED_PORT 1023
111
112
113
114
115
116
117
118struct cfs_psdev_file {
119 unsigned long off;
120 void *private_data;
121 unsigned long reserved1;
122 unsigned long reserved2;
123};
124
125struct cfs_psdev_ops {
126 int (*p_open)(unsigned long, void *);
127 int (*p_close)(unsigned long, void *);
128 int (*p_read)(struct cfs_psdev_file *, char *, unsigned long);
129 int (*p_write)(struct cfs_psdev_file *, char *, unsigned long);
130 int (*p_ioctl)(struct cfs_psdev_file *, unsigned long, void *);
131};
132
133
134
135
136
137void cfs_enter_debugger(void);
138
139
140
141
142int unshare_fs_struct(void);
143sigset_t cfs_get_blocked_sigs(void);
144sigset_t cfs_block_allsigs(void);
145sigset_t cfs_block_sigs(unsigned long sigs);
146sigset_t cfs_block_sigsinv(unsigned long sigs);
147void cfs_restore_sigs(sigset_t);
148int cfs_signal_pending(void);
149void cfs_clear_sigpending(void);
150
151
152
153
154
155
156unsigned int cfs_rand(void);
157
158void cfs_srand(unsigned int, unsigned int);
159void cfs_get_random_bytes(void *buf, int size);
160
161#include "libcfs_debug.h"
162#include "libcfs_cpu.h"
163#include "libcfs_private.h"
164#include "libcfs_ioctl.h"
165#include "libcfs_prim.h"
166#include "libcfs_time.h"
167#include "libcfs_string.h"
168#include "libcfs_kernelcomm.h"
169#include "libcfs_workitem.h"
170#include "libcfs_hash.h"
171#include "libcfs_fail.h"
172#include "libcfs_crypto.h"
173
174
175static inline void *__container_of(void *ptr, unsigned long shift)
176{
177 if (unlikely(IS_ERR(ptr) || ptr == NULL))
178 return ptr;
179 return (char *)ptr - shift;
180}
181
182#define container_of0(ptr, type, member) \
183 ((type *)__container_of((void *)(ptr), offsetof(type, member)))
184
185#define _LIBCFS_H
186
187#endif
188