Whamcloud - gitweb
LU-2456 lnet: DLC Feature dynamic net config
[fs/lustre-release.git] / libcfs / include / libcfs / darwin / darwin-tcpip.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 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * libcfs/include/libcfs/darwin/darwin-tcpip.h
35  *
36  * Basic library routines.
37  */
38
39 #ifndef __LIBCFS_DARWIN_TCPIP_H__
40 #define __LIBCFS_DARWIN_TCPIP_H__
41
42 #ifdef __KERNEL__
43 #include <sys/socket.h>
44
45 #ifdef __DARWIN8__
46
47 struct socket;
48
49 typedef void    (*so_upcall)(socket_t sock, void* arg, int waitf);
50
51 #define CFS_SOCK_UPCALL         0x1
52 #define CFS_SOCK_DOWN           0x2
53
54 #define CFS_SOCK_MAGIC          0xbabeface
55
56 typedef struct cfs_socket {
57         socket_t        s_so;
58         int             s_magic;
59         int             s_flags;
60         so_upcall       s_upcall;
61         void           *s_upcallarg;
62 } cfs_socket_t;
63
64
65 /* cfs_socket_t to bsd socket */
66 #define C2B_SOCK(s)             ((s)->s_so)     
67
68 static inline int get_sock_intopt(socket_t so, int opt)
69 {
70         int     val, len;
71         int     rc;
72
73         /*
74          * sock_getsockopt will take a lock(mutex) for socket,
75          * so it can be blocked. So be careful while using 
76          * them.
77          */
78         len = sizeof(val);
79         rc = sock_getsockopt(so, SOL_SOCKET, opt, &val, &len);
80         assert(rc == 0);
81         return val;
82 }
83
84 #define SOCK_ERROR(s)           get_sock_intopt(C2B_SOCK(s), SO_ERROR)        
85 /* #define SOCK_WMEM_QUEUED(s)     (0) */
86 #define SOCK_WMEM_QUEUED(s)     get_sock_intopt(C2B_SOCK(s), SO_NWRITE)
87 /* XXX Liang: no reliable way to get it in Darwin8.x */
88 #define SOCK_TEST_NOSPACE(s)    (0)
89
90 void libcfs_sock_set_cb(cfs_socket_t *sock, so_upcall callback, void *arg);
91 void libcfs_sock_reset_cb(cfs_socket_t *sock);
92
93 #else /* !__DARWIN8__ */
94
95 #define SOCK_WMEM_QUEUED(so)    ((so)->so_snd.sb_cc)
96 #define SOCK_ERROR(so)          ((so)->so_error)
97
98 #define SOCK_TEST_NOSPACE(so)   (sbspace(&(so)->so_snd) < (so)->so_snd.sb_lowat)
99
100 #endif /* !__DARWIN8__ */
101
102 #endif  /* __KERNEL END */
103
104 #endif  /* __XNU_CFS_TYPES_H__ */