Whamcloud - gitweb
LU-2675 lnet: add lnet/nidstr.h
[fs/lustre-release.git] / libcfs / include / libcfs / libcfs_private.h
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  * libcfs/include/libcfs/libcfs_private.h
37  *
38  * Various defines for libcfs.
39  *
40  */
41
42 #ifndef __LIBCFS_PRIVATE_H__
43 #define __LIBCFS_PRIVATE_H__
44
45 #ifndef DEBUG_SUBSYSTEM
46 # define DEBUG_SUBSYSTEM S_UNDEFINED
47 #endif
48
49 #ifdef __KERNEL__
50
51 #ifdef LIBCFS_DEBUG
52
53 /*
54  * When this is on, LASSERT macro includes check for assignment used instead
55  * of equality check, but doesn't have unlikely(). Turn this on from time to
56  * time to make test-builds. This shouldn't be on for production release.
57  */
58 #define LASSERT_CHECKED (0)
59
60 #if LASSERT_CHECKED
61 /*
62  * Assertion.
63  *
64  * Strange construction with empty "then" clause is used to trigger compiler
65  * warnings on the assertions of the form LASSERT(a = b);
66  *
67  * "warning: suggest parentheses around assignment used as truth value"
68  *
69  * requires -Wall. Unfortunately this rules out use of likely/unlikely.
70  */
71 #define LASSERTF(cond, fmt, ...)                                        \
72 do {                                                                    \
73         if (cond)                                                       \
74                 ;                                                       \
75         else {                                                          \
76                 LIBCFS_DEBUG_MSG_DATA_DECL(__msg_data, D_EMERG, NULL);  \
77                 libcfs_debug_msg(&__msg_data,                           \
78                                  "ASSERTION( %s ) failed: " fmt, #cond, \
79                                  ## __VA_ARGS__);                       \
80                 lbug_with_loc(&__msg_data);                             \
81         }                                                               \
82 } while (0)
83
84 #define LASSERT(cond) LASSERTF(cond, "\n")
85
86 #else /* !LASSERT_CHECKED */
87
88 #define LASSERTF(cond, fmt, ...)                                        \
89 do {                                                                    \
90         if (unlikely(!(cond))) {                                        \
91                 LIBCFS_DEBUG_MSG_DATA_DECL(__msg_data, D_EMERG, NULL);  \
92                 libcfs_debug_msg(&__msg_data,                           \
93                                  "ASSERTION( %s ) failed: " fmt, #cond, \
94                                  ## __VA_ARGS__);                       \
95                 lbug_with_loc(&__msg_data);                             \
96         }                                                               \
97 } while (0)
98
99 #define LASSERT(cond) LASSERTF(cond, "\n")
100 #endif /* !LASSERT_CHECKED */
101 #else /* !LIBCFS_DEBUG */
102 /* sizeof is to use expression without evaluating it. */
103 # define LASSERT(e) ((void)sizeof!!(e))
104 # define LASSERTF(cond, ...) ((void)sizeof!!(cond))
105 #endif /* !LIBCFS_DEBUG */
106
107 #ifdef CONFIG_LUSTRE_DEBUG_EXPENSIVE_CHECK
108 /**
109  * This is for more expensive checks that one doesn't want to be enabled all
110  * the time. LINVRNT() has to be explicitly enabled by --enable-invariants
111  * configure option.
112  */
113 # define LINVRNT(exp) LASSERT(exp)
114 #else
115 # define LINVRNT(exp) ((void)sizeof!!(exp))
116 #endif
117
118 #define KLASSERT(e) LASSERT(e)
119
120 void lbug_with_loc(struct libcfs_debug_msg_data *) __attribute__((noreturn));
121
122 #define LBUG()                                                          \
123 do {                                                                    \
124         LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_EMERG, NULL);             \
125         lbug_with_loc(&msgdata);                                        \
126 } while(0)
127
128 extern atomic_t libcfs_kmemory;
129 /*
130  * Memory
131  */
132 #ifdef LIBCFS_DEBUG
133
134 # define libcfs_kmem_inc(ptr, size)             \
135 do {                                            \
136         atomic_add(size, &libcfs_kmemory);      \
137 } while (0)
138
139 # define libcfs_kmem_dec(ptr, size)             \
140 do {                                            \
141         atomic_sub(size, &libcfs_kmemory);      \
142 } while (0)
143
144 # define libcfs_kmem_read()                     \
145         atomic_read(&libcfs_kmemory)
146
147 #else
148 # define libcfs_kmem_inc(ptr, size) do {} while (0)
149 # define libcfs_kmem_dec(ptr, size) do {} while (0)
150 # define libcfs_kmem_read()     (0)
151 #endif /* LIBCFS_DEBUG */
152
153 #ifndef LIBCFS_VMALLOC_SIZE
154 #define LIBCFS_VMALLOC_SIZE        (2 << PAGE_CACHE_SHIFT) /* 2 pages */
155 #endif
156
157 #define LIBCFS_ALLOC_PRE(size, mask)                                        \
158 do {                                                                        \
159         LASSERT(!in_interrupt() ||                                          \
160                 ((size) <= LIBCFS_VMALLOC_SIZE &&                           \
161                  ((mask) & GFP_ATOMIC)) != 0);                      \
162 } while (0)
163
164 #define LIBCFS_ALLOC_POST(ptr, size)                                        \
165 do {                                                                        \
166         if (unlikely((ptr) == NULL)) {                                      \
167                 CERROR("LNET: out of memory at %s:%d (tried to alloc '"     \
168                        #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size));  \
169                 CERROR("LNET: %d total bytes allocated by lnet\n",          \
170                        libcfs_kmem_read());                                 \
171         } else {                                                            \
172                 libcfs_kmem_inc((ptr), (size));                             \
173                 CDEBUG(D_MALLOC, "alloc '" #ptr "': %d at %p (tot %d).\n",  \
174                        (int)(size), (ptr), libcfs_kmem_read());             \
175         }                                                                   \
176 } while (0)
177
178 /**
179  * allocate memory with GFP flags @mask
180  * The allocated memory is zeroed-out.
181  */
182 #define LIBCFS_ALLOC_GFP(ptr, size, mask)                                   \
183 do {                                                                        \
184         LIBCFS_ALLOC_PRE((size), (mask));                                   \
185         (ptr) = (size) <= LIBCFS_VMALLOC_SIZE ?                             \
186                 kzalloc((size), (mask)) : vzalloc(size);                    \
187         LIBCFS_ALLOC_POST((ptr), (size));                                   \
188 } while (0)
189
190 /**
191  * default allocator
192  */
193 #define LIBCFS_ALLOC(ptr, size) \
194         LIBCFS_ALLOC_GFP(ptr, size, GFP_NOFS)
195
196 /**
197  * non-sleeping allocator
198  */
199 #define LIBCFS_ALLOC_ATOMIC(ptr, size) \
200         LIBCFS_ALLOC_GFP(ptr, size, GFP_ATOMIC)
201
202 /**
203  * allocate memory for specified CPU partition
204  *   \a cptab != NULL, \a cpt is CPU partition id of \a cptab
205  *   \a cptab == NULL, \a cpt is HW NUMA node id
206  * The allocated memory is zeroed-out.
207  */
208 #define LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, mask)                   \
209 do {                                                                        \
210         LIBCFS_ALLOC_PRE((size), (mask));                                   \
211         (ptr) = (size) <= LIBCFS_VMALLOC_SIZE ?                             \
212                 cfs_cpt_malloc((cptab), (cpt), (size), (mask) | __GFP_ZERO) : \
213                 cfs_cpt_vzalloc((cptab), (cpt), (size));                    \
214         LIBCFS_ALLOC_POST((ptr), (size));                                   \
215 } while (0)
216
217 /** default numa allocator */
218 #define LIBCFS_CPT_ALLOC(ptr, cptab, cpt, size)                             \
219         LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, GFP_NOFS)
220
221 #define LIBCFS_FREE(ptr, size)                                          \
222 do {                                                                    \
223         int s = (size);                                                 \
224         if (unlikely((ptr) == NULL)) {                                  \
225                 CERROR("LIBCFS: free NULL '" #ptr "' (%d bytes) at "    \
226                        "%s:%d\n", s, __FILE__, __LINE__);               \
227                 break;                                                  \
228         }                                                               \
229         libcfs_kmem_dec((ptr), s);                                      \
230         CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n",     \
231                s, (ptr), libcfs_kmem_read());                           \
232         if (unlikely(s > LIBCFS_VMALLOC_SIZE))                          \
233                 vfree(ptr);                                             \
234         else                                                            \
235                 kfree(ptr);                                             \
236 } while (0)
237
238 /******************************************************************************/
239
240 /* htonl hack - either this, or compile with -O2. Stupid byteorder/generic.h */
241 #if defined(__GNUC__) && (__GNUC__ >= 2) && !defined(__OPTIMIZE__)
242 #define ___htonl(x) __cpu_to_be32(x)
243 #define ___htons(x) __cpu_to_be16(x)
244 #define ___ntohl(x) __be32_to_cpu(x)
245 #define ___ntohs(x) __be16_to_cpu(x)
246 #define htonl(x) ___htonl(x)
247 #define ntohl(x) ___ntohl(x)
248 #define htons(x) ___htons(x)
249 #define ntohs(x) ___ntohs(x)
250 #endif
251
252 void libcfs_debug_dumpstack(struct task_struct *tsk);
253 void libcfs_run_upcall(char **argv);
254 void libcfs_run_lbug_upcall(struct libcfs_debug_msg_data *);
255 void libcfs_debug_dumplog(void);
256 int libcfs_debug_init(unsigned long bufsize);
257 int libcfs_debug_cleanup(void);
258 int libcfs_debug_clear_buffer(void);
259 int libcfs_debug_mark_buffer(const char *text);
260
261 void libcfs_debug_set_level(unsigned int debug_level);
262
263 #else  /* !__KERNEL__ */
264 # ifdef LIBCFS_DEBUG
265 #  undef NDEBUG
266 #  include <assert.h>
267 #  define LASSERT(e)     assert(e)
268 #  define LASSERTF(cond, ...)                                                  \
269 do {                                                                           \
270           if (!(cond))                                                         \
271                 CERROR(__VA_ARGS__);                                           \
272           assert(cond);                                                        \
273 } while (0)
274 #  define LBUG()   assert(0)
275 #  ifdef CONFIG_LUSTRE_DEBUG_EXPENSIVE_CHECK
276 #   define LINVRNT(exp) LASSERT(exp)
277 #  else
278 #   define LINVRNT(exp) ((void)sizeof!!(exp))
279 #  endif
280 # else
281 #  define LASSERT(e) ((void)sizeof!!(e))
282 #  define LASSERTF(cond, ...) ((void)sizeof!!(cond))
283 #  define LBUG()   ((void)(0))
284 #  define LINVRNT(exp) ((void)sizeof!!(exp))
285 # endif /* LIBCFS_DEBUG */
286 # define KLASSERT(e) ((void)0)
287 # define printk printf
288 #define LIBCFS_ALLOC_GFP(ptr, size, mask)       \
289 do {                                            \
290         (ptr) = calloc(1, size);                \
291 } while (0)
292 # define LIBCFS_FREE(ptr, size) do { free(ptr); } while((size) - (size))
293 # define LIBCFS_ALLOC(ptr, size)                                \
294          LIBCFS_ALLOC_GFP(ptr, size, 0)
295 # define LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, mask)      \
296          LIBCFS_ALLOC(ptr, size)
297 # define LIBCFS_CPT_ALLOC(ptr, cptab, cpt, size)                \
298          LIBCFS_ALLOC(ptr, size)
299
300 void libcfs_debug_dumplog(void);
301 int libcfs_debug_init(unsigned long bufsize);
302 int libcfs_debug_cleanup(void);
303
304 #define libcfs_debug_dumpstack(tsk)     ((void)0)
305
306 /*
307  * Generic compiler-dependent macros required for kernel
308  * build go below this comment. Actual compiler/compiler version
309  * specific implementations come from the above header files
310  */
311 #define likely(x)      __builtin_expect(!!(x), 1)
312 #define unlikely(x)    __builtin_expect(!!(x), 0)
313 /* !__KERNEL__ */
314 #endif
315
316 struct cfs_cpt_table;
317
318 /*
319  * allocate per-cpu-partition data, returned value is an array of pointers,
320  * variable can be indexed by CPU ID.
321  *      cptable != NULL: size of array is number of CPU partitions
322  *      cptable == NULL: size of array is number of HW cores
323  */
324 void *cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size);
325 /*
326  * destory per-cpu-partition variable
327  */
328 void  cfs_percpt_free(void *vars);
329 int   cfs_percpt_number(void *vars);
330 void *cfs_percpt_current(void *vars);
331 void *cfs_percpt_index(void *vars, int idx);
332
333 #define cfs_percpt_for_each(var, i, vars)               \
334         for (i = 0; i < cfs_percpt_number(vars) &&      \
335                     ((var) = (vars)[i]) != NULL; i++)
336
337 /*
338  * allocate a variable array, returned value is an array of pointers.
339  * Caller can specify length of array by count.
340  */
341 void *cfs_array_alloc(int count, unsigned int size);
342 void  cfs_array_free(void *vars);
343
344 #define LASSERT_ATOMIC_ENABLED          (1)
345
346 #if LASSERT_ATOMIC_ENABLED
347
348 /** assert value of @a is equal to @v */
349 #define LASSERT_ATOMIC_EQ(a, v)                                 \
350 do {                                                            \
351         LASSERTF(atomic_read(a) == v,                       \
352                  "value: %d\n", atomic_read((a)));          \
353 } while (0)
354
355 /** assert value of @a is unequal to @v */
356 #define LASSERT_ATOMIC_NE(a, v)                                 \
357 do {                                                            \
358         LASSERTF(atomic_read(a) != v,                       \
359                  "value: %d\n", atomic_read((a)));          \
360 } while (0)
361
362 /** assert value of @a is little than @v */
363 #define LASSERT_ATOMIC_LT(a, v)                                 \
364 do {                                                            \
365         LASSERTF(atomic_read(a) < v,                        \
366                  "value: %d\n", atomic_read((a)));          \
367 } while (0)
368
369 /** assert value of @a is little/equal to @v */
370 #define LASSERT_ATOMIC_LE(a, v)                                 \
371 do {                                                            \
372         LASSERTF(atomic_read(a) <= v,                       \
373                  "value: %d\n", atomic_read((a)));          \
374 } while (0)
375
376 /** assert value of @a is great than @v */
377 #define LASSERT_ATOMIC_GT(a, v)                                 \
378 do {                                                            \
379         LASSERTF(atomic_read(a) > v,                        \
380                  "value: %d\n", atomic_read((a)));          \
381 } while (0)
382
383 /** assert value of @a is great/equal to @v */
384 #define LASSERT_ATOMIC_GE(a, v)                                 \
385 do {                                                            \
386         LASSERTF(atomic_read(a) >= v,                       \
387                  "value: %d\n", atomic_read((a)));          \
388 } while (0)
389
390 /** assert value of @a is great than @v1 and little than @v2 */
391 #define LASSERT_ATOMIC_GT_LT(a, v1, v2)                         \
392 do {                                                            \
393         int __v = atomic_read(a);                           \
394         LASSERTF(__v > v1 && __v < v2, "value: %d\n", __v);     \
395 } while (0)
396
397 /** assert value of @a is great than @v1 and little/equal to @v2 */
398 #define LASSERT_ATOMIC_GT_LE(a, v1, v2)                         \
399 do {                                                            \
400         int __v = atomic_read(a);                           \
401         LASSERTF(__v > v1 && __v <= v2, "value: %d\n", __v);    \
402 } while (0)
403
404 /** assert value of @a is great/equal to @v1 and little than @v2 */
405 #define LASSERT_ATOMIC_GE_LT(a, v1, v2)                         \
406 do {                                                            \
407         int __v = atomic_read(a);                           \
408         LASSERTF(__v >= v1 && __v < v2, "value: %d\n", __v);    \
409 } while (0)
410
411 /** assert value of @a is great/equal to @v1 and little/equal to @v2 */
412 #define LASSERT_ATOMIC_GE_LE(a, v1, v2)                         \
413 do {                                                            \
414         int __v = atomic_read(a);                           \
415         LASSERTF(__v >= v1 && __v <= v2, "value: %d\n", __v);   \
416 } while (0)
417
418 #else /* !LASSERT_ATOMIC_ENABLED */
419
420 #define LASSERT_ATOMIC_EQ(a, v)                 do {} while (0)
421 #define LASSERT_ATOMIC_NE(a, v)                 do {} while (0)
422 #define LASSERT_ATOMIC_LT(a, v)                 do {} while (0)
423 #define LASSERT_ATOMIC_LE(a, v)                 do {} while (0)
424 #define LASSERT_ATOMIC_GT(a, v)                 do {} while (0)
425 #define LASSERT_ATOMIC_GE(a, v)                 do {} while (0)
426 #define LASSERT_ATOMIC_GT_LT(a, v1, v2)         do {} while (0)
427 #define LASSERT_ATOMIC_GT_LE(a, v1, v2)         do {} while (0)
428 #define LASSERT_ATOMIC_GE_LT(a, v1, v2)         do {} while (0)
429 #define LASSERT_ATOMIC_GE_LE(a, v1, v2)         do {} while (0)
430
431 #endif /* LASSERT_ATOMIC_ENABLED */
432
433 #define LASSERT_ATOMIC_ZERO(a)                  LASSERT_ATOMIC_EQ(a, 0)
434 #define LASSERT_ATOMIC_POS(a)                   LASSERT_ATOMIC_GT(a, 0)
435
436 #define CFS_ALLOC_PTR(ptr)      LIBCFS_ALLOC(ptr, sizeof (*(ptr)));
437 #define CFS_FREE_PTR(ptr)       LIBCFS_FREE(ptr, sizeof (*(ptr)));
438
439 /*
440  * percpu partition lock
441  *
442  * There are some use-cases like this in Lustre:
443  * . each CPU partition has it's own private data which is frequently changed,
444  *   and mostly by the local CPU partition.
445  * . all CPU partitions share some global data, these data are rarely changed.
446  *
447  * LNet is typical example.
448  * CPU partition lock is designed for this kind of use-cases:
449  * . each CPU partition has it's own private lock
450  * . change on private data just needs to take the private lock
451  * . read on shared data just needs to take _any_ of private locks
452  * . change on shared data needs to take _all_ private locks,
453  *   which is slow and should be really rare.
454  */
455
456 enum {
457         CFS_PERCPT_LOCK_EX      = -1, /* negative */
458 };
459
460 #ifdef __KERNEL__
461
462 struct cfs_percpt_lock {
463         /* cpu-partition-table for this lock */
464         struct cfs_cpt_table    *pcl_cptab;
465         /* exclusively locked */
466         unsigned int            pcl_locked;
467         /* private lock table */
468         spinlock_t              **pcl_locks;
469 };
470
471 /* return number of private locks */
472 #define cfs_percpt_lock_num(pcl)        cfs_cpt_number(pcl->pcl_cptab)
473
474 #else /* !__KERNEL__ */
475
476 # ifdef HAVE_LIBPTHREAD
477
478 struct cfs_percpt_lock {
479         pthread_mutex_t         pcl_mutex;
480 };
481
482 # else /* !HAVE_LIBPTHREAD */
483
484 struct cfs_percpt_lock {
485         int                     pcl_lock;
486 };
487
488 static const struct cfs_percpt_lock CFS_PERCPT_LOCK_MAGIC;
489
490 # endif /* HAVE_LIBPTHREAD */
491 # define cfs_percpt_lock_num(pcl)        1
492 #endif /* __KERNEL__ */
493
494 /*
495  * create a cpu-partition lock based on CPU partition table \a cptab,
496  * each private lock has extra \a psize bytes padding data
497  */
498 struct cfs_percpt_lock *cfs_percpt_lock_alloc(struct cfs_cpt_table *cptab);
499 /* destroy a cpu-partition lock */
500 void cfs_percpt_lock_free(struct cfs_percpt_lock *pcl);
501
502 /* lock private lock \a index of \a pcl */
503 void cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index);
504 /* unlock private lock \a index of \a pcl */
505 void cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index);
506 /* create percpt (atomic) refcount based on @cptab */
507 atomic_t **cfs_percpt_atomic_alloc(struct cfs_cpt_table *cptab, int val);
508 /* destroy percpt refcount */
509 void cfs_percpt_atomic_free(atomic_t **refs);
510 /* return sum of all percpu refs */
511 int cfs_percpt_atomic_summary(atomic_t **refs);
512
513
514 /** Compile-time assertion.
515
516  * Check an invariant described by a constant expression at compile time by
517  * forcing a compiler error if it does not hold.  \a cond must be a constant
518  * expression as defined by the ISO C Standard:
519  *
520  *       6.8.4.2  The switch statement
521  *       ....
522  *       [#3] The expression of each case label shall be  an  integer
523  *       constant   expression  and  no  two  of  the  case  constant
524  *       expressions in the same switch statement shall have the same
525  *       value  after  conversion...
526  *
527  */
528 #define CLASSERT(cond) do {switch (1) {case (cond): case 0: break; } } while (0)
529
530 /* implication */
531 #define ergo(a, b) (!(a) || (b))
532 /* logical equivalence */
533 #define equi(a, b) (!!(a) == !!(b))
534
535 #ifndef CFS_CURRENT_TIME
536 # define CFS_CURRENT_TIME time(0)
537 #endif
538
539 struct libcfs_device_userstate
540 {
541         int             ldu_memhog_pages;
542         struct page     *ldu_memhog_root_page;
543 };
544
545 /* what used to be in portals_lib.h */
546 #ifndef MIN
547 # define MIN(a,b) (((a)<(b)) ? (a): (b))
548 #endif
549 #ifndef MAX
550 # define MAX(a,b) (((a)>(b)) ? (a): (b))
551 #endif
552
553 #define MKSTR(ptr) ((ptr))? (ptr) : ""
554
555 static inline size_t cfs_size_round4(size_t val)
556 {
557         return (val + 3) & (~0x3);
558 }
559
560 #ifndef HAVE_CFS_SIZE_ROUND
561 static inline size_t cfs_size_round(size_t val)
562 {
563         return (val + 7) & (~0x7);
564 }
565 #define HAVE_CFS_SIZE_ROUND
566 #endif
567
568 static inline size_t cfs_size_round16(size_t val)
569 {
570         return (val + 0xf) & (~0xf);
571 }
572
573 static inline size_t cfs_size_round32(size_t val)
574 {
575         return (val + 0x1f) & (~0x1f);
576 }
577
578 static inline size_t cfs_size_round0(size_t val)
579 {
580         if (!val)
581                 return 0;
582         return (val + 1 + 7) & (~0x7);
583 }
584
585 static inline size_t cfs_round_strlen(char *fset)
586 {
587         return cfs_size_round(strlen(fset) + 1);
588 }
589
590 /* roundup \a val to power2 */
591 static inline size_t cfs_power2_roundup(size_t val)
592 {
593         if (val != LOWEST_BIT_SET(val)) { /* not a power of 2 already */
594                 do {
595                         val &= ~LOWEST_BIT_SET(val);
596                 } while (val != LOWEST_BIT_SET(val));
597                 /* ...and round up */
598                 val <<= 1;
599         }
600         return val;
601 }
602
603 #define LOGL(var,len,ptr)                                       \
604 do {                                                            \
605         if (var)                                                \
606                 memcpy((char *)ptr, (const char *)var, len);    \
607         ptr += cfs_size_round(len);                             \
608 } while (0)
609
610 #define LOGU(var,len,ptr)                                       \
611 do {                                                            \
612         if (var)                                                \
613                 memcpy((char *)var, (const char *)ptr, len);    \
614         ptr += cfs_size_round(len);                             \
615 } while (0)
616
617 /**
618  *  Lustre Network Driver types.
619  */
620 enum {
621         /* Only add to these values (i.e. don't ever change or redefine them):
622          * network addresses depend on them... */
623         QSWLND    = 1,
624         SOCKLND   = 2,
625         GMLND     = 3, /* obsolete, keep it so that libcfs_nid2str works */
626         PTLLND    = 4,
627         O2IBLND   = 5,
628         CIBLND    = 6,
629         OPENIBLND = 7,
630         IIBLND    = 8,
631         LOLND     = 9,
632         RALND     = 10,
633         VIBLND    = 11,
634         MXLND     = 12,
635         GNILND    = 13,
636         GNIIPLND  = 14,
637 };
638
639 #endif