Whamcloud - gitweb
* ranal passes netregression
[fs/lustre-release.git] / lnet / include / linux / portals_lib.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Basic library routines. 
22  *
23  */
24
25 #ifndef _PORTALS_LIB_H
26 #define _PORTALS_LIB_H
27
28 #ifndef __KERNEL__
29 # include <string.h>
30 #else 
31 # include <asm/types.h>
32 #endif
33
34 #undef MIN
35 #define MIN(a,b) (((a)<(b)) ? (a): (b))
36 #undef MAX
37 #define MAX(a,b) (((a)>(b)) ? (a): (b))
38 #define MKSTR(ptr) ((ptr))? (ptr) : ""
39
40 static inline int size_round (int val)
41 {
42         return (val + 7) & (~0x7);
43 }
44
45 static inline int size_round16(int val)
46 {
47         return (val + 0xf) & (~0xf);
48 }
49
50 static inline int size_round32(int val)
51 {
52         return (val + 0x1f) & (~0x1f);
53 }
54
55 static inline int size_round0(int val)
56 {
57         if (!val)
58                 return 0;
59         return (val + 1 + 7) & (~0x7);
60 }
61
62 static inline size_t round_strlen(char *fset)
63 {
64         return size_round(strlen(fset) + 1);
65 }
66
67 #define LOGL(var,len,ptr)                                       \
68 do {                                                            \
69         if (var)                                                \
70                 memcpy((char *)ptr, (const char *)var, len);    \
71         ptr += size_round(len);                                 \
72 } while (0)
73
74 #define LOGU(var,len,ptr)                                       \
75 do {                                                            \
76         if (var)                                                \
77                 memcpy((char *)var, (const char *)ptr, len);    \
78         ptr += size_round(len);                                 \
79 } while (0)
80
81 #define LOGL0(var,len,ptr)                              \
82 do {                                                    \
83         if (!len)                                       \
84                 break;                                  \
85         memcpy((char *)ptr, (const char *)var, len);    \
86         *((char *)(ptr) + len) = 0;                     \
87         ptr += size_round(len + 1);                     \
88 } while (0)
89
90 #endif /* _PORTALS_LIB_H */