]>
Commit | Line | Data |
---|---|---|
d7e09d03 PT |
1 | /* |
2 | * GPL HEADER START | |
3 | * | |
4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 only, | |
8 | * as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License version 2 for more details (a copy is included | |
14 | * in the LICENSE file that accompanied this code). | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * version 2 along with this program; If not, see | |
18 | * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf | |
19 | * | |
20 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
21 | * CA 95054 USA or visit www.sun.com if you need additional information or | |
22 | * have any questions. | |
23 | * | |
24 | * GPL HEADER END | |
25 | */ | |
26 | /* | |
27 | * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | * | |
30 | * Copyright (c) 2011, 2012, Intel Corporation. | |
31 | */ | |
32 | /* | |
33 | * This file is part of Lustre, http://www.lustre.org/ | |
34 | * Lustre is a trademark of Sun Microsystems, Inc. | |
35 | */ | |
36 | ||
37 | #ifndef __LIBCFS_LIBCFS_H__ | |
38 | #define __LIBCFS_LIBCFS_H__ | |
39 | ||
40 | #if !__GNUC__ | |
41 | #define __attribute__(x) | |
42 | #endif | |
43 | ||
9fdaf8c0 | 44 | #include "linux/libcfs.h" |
cad7aa13 | 45 | #include <linux/gfp.h> |
d7e09d03 PT |
46 | |
47 | #include "curproc.h" | |
48 | ||
49 | #ifndef offsetof | |
a393fd54 | 50 | # define offsetof(typ, memb) ((long)(long_ptr_t)((char *)&(((typ *)0)->memb))) |
d7e09d03 PT |
51 | #endif |
52 | ||
53 | #ifndef ARRAY_SIZE | |
a393fd54 | 54 | #define ARRAY_SIZE(a) ((sizeof(a)) / (sizeof((a)[0]))) |
d7e09d03 PT |
55 | #endif |
56 | ||
57 | #if !defined(swap) | |
a393fd54 | 58 | #define swap(x, y) do { typeof(x) z = x; x = y; y = z; } while (0) |
d7e09d03 PT |
59 | #endif |
60 | ||
61 | #if !defined(container_of) | |
62 | /* given a pointer @ptr to the field @member embedded into type (usually | |
63 | * struct) @type, return pointer to the embedding instance of @type. */ | |
64 | #define container_of(ptr, type, member) \ | |
65 | ((type *)((char *)(ptr)-(char *)(&((type *)0)->member))) | |
66 | #endif | |
67 | ||
68 | static 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 | * Lustre Error Checksum: calculates checksum | |
79 | * of Hex number by XORing each bit. | |
80 | */ | |
81 | #define LERRCHKSUM(hexnum) (((hexnum) & 0xf) ^ ((hexnum) >> 4 & 0xf) ^ \ | |
82 | ((hexnum) >> 8 & 0xf)) | |
83 | ||
d7e09d03 PT |
84 | #define LUSTRE_SRV_LNET_PID LUSTRE_LNET_PID |
85 | ||
d7e09d03 PT |
86 | #include <linux/list.h> |
87 | ||
d7e09d03 PT |
88 | /* libcfs tcpip */ |
89 | int libcfs_ipif_query(char *name, int *up, __u32 *ip, __u32 *mask); | |
90 | int libcfs_ipif_enumerate(char ***names); | |
91 | void libcfs_ipif_free_enumeration(char **names, int n); | |
e327dc88 GKH |
92 | int libcfs_sock_listen(struct socket **sockp, __u32 ip, int port, int backlog); |
93 | int libcfs_sock_accept(struct socket **newsockp, struct socket *sock); | |
94 | void libcfs_sock_abort_accept(struct socket *sock); | |
95 | int libcfs_sock_connect(struct socket **sockp, int *fatal, | |
d7e09d03 PT |
96 | __u32 local_ip, int local_port, |
97 | __u32 peer_ip, int peer_port); | |
e327dc88 GKH |
98 | int libcfs_sock_setbuf(struct socket *socket, int txbufsize, int rxbufsize); |
99 | int libcfs_sock_getbuf(struct socket *socket, int *txbufsize, int *rxbufsize); | |
100 | int libcfs_sock_getaddr(struct socket *socket, int remote, __u32 *ip, int *port); | |
101 | int libcfs_sock_write(struct socket *sock, void *buffer, int nob, int timeout); | |
102 | int libcfs_sock_read(struct socket *sock, void *buffer, int nob, int timeout); | |
103 | void libcfs_sock_release(struct socket *sock); | |
d7e09d03 | 104 | |
d7e09d03 PT |
105 | /* need both kernel and user-land acceptor */ |
106 | #define LNET_ACCEPTOR_MIN_RESERVED_PORT 512 | |
107 | #define LNET_ACCEPTOR_MAX_RESERVED_PORT 1023 | |
108 | ||
109 | /* | |
110 | * libcfs pseudo device operations | |
111 | * | |
d7e09d03 PT |
112 | * It's just draft now. |
113 | */ | |
114 | ||
115 | struct cfs_psdev_file { | |
116 | unsigned long off; | |
117 | void *private_data; | |
118 | unsigned long reserved1; | |
119 | unsigned long reserved2; | |
120 | }; | |
121 | ||
122 | struct cfs_psdev_ops { | |
123 | int (*p_open)(unsigned long, void *); | |
124 | int (*p_close)(unsigned long, void *); | |
125 | int (*p_read)(struct cfs_psdev_file *, char *, unsigned long); | |
126 | int (*p_write)(struct cfs_psdev_file *, char *, unsigned long); | |
127 | int (*p_ioctl)(struct cfs_psdev_file *, unsigned long, void *); | |
128 | }; | |
129 | ||
130 | /* | |
131 | * Drop into debugger, if possible. Implementation is provided by platform. | |
132 | */ | |
133 | ||
134 | void cfs_enter_debugger(void); | |
135 | ||
136 | /* | |
137 | * Defined by platform | |
138 | */ | |
139 | int unshare_fs_struct(void); | |
140 | sigset_t cfs_get_blocked_sigs(void); | |
141 | sigset_t cfs_block_allsigs(void); | |
142 | sigset_t cfs_block_sigs(unsigned long sigs); | |
143 | sigset_t cfs_block_sigsinv(unsigned long sigs); | |
144 | void cfs_restore_sigs(sigset_t); | |
145 | int cfs_signal_pending(void); | |
146 | void cfs_clear_sigpending(void); | |
147 | ||
d7e09d03 PT |
148 | /* |
149 | * Random number handling | |
150 | */ | |
151 | ||
152 | /* returns a random 32-bit integer */ | |
153 | unsigned int cfs_rand(void); | |
154 | /* seed the generator */ | |
155 | void cfs_srand(unsigned int, unsigned int); | |
156 | void cfs_get_random_bytes(void *buf, int size); | |
157 | ||
9fdaf8c0 GKH |
158 | #include "libcfs_debug.h" |
159 | #include "libcfs_cpu.h" | |
160 | #include "libcfs_private.h" | |
161 | #include "libcfs_ioctl.h" | |
162 | #include "libcfs_prim.h" | |
163 | #include "libcfs_time.h" | |
164 | #include "libcfs_string.h" | |
165 | #include "libcfs_kernelcomm.h" | |
166 | #include "libcfs_workitem.h" | |
167 | #include "libcfs_hash.h" | |
9fdaf8c0 | 168 | #include "libcfs_fail.h" |
9fdaf8c0 | 169 | #include "libcfs_crypto.h" |
d7e09d03 PT |
170 | |
171 | /* container_of depends on "likely" which is defined in libcfs_private.h */ | |
172 | static inline void *__container_of(void *ptr, unsigned long shift) | |
173 | { | |
174 | if (unlikely(IS_ERR(ptr) || ptr == NULL)) | |
175 | return ptr; | |
176 | else | |
177 | return (char *)ptr - shift; | |
178 | } | |
179 | ||
180 | #define container_of0(ptr, type, member) \ | |
181 | ((type *)__container_of((void *)(ptr), offsetof(type, member))) | |
182 | ||
d7e09d03 PT |
183 | #define _LIBCFS_H |
184 | ||
185 | #endif /* _LIBCFS_H */ |