Whamcloud - gitweb
5f31d1d2dbb9fbbeb3d5f2ac0b8e7df0c324e903
[fs/lustre-release.git] / libcfs / include / libcfs / libcfs_kernelcomm.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2009 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * Author: Nathan Rutman <nathan.rutman@sun.com>
37  *
38  * libcfs/include/libcfs/libcfs_kernelcomm.h
39  *
40  * Kernel <-> userspace communication routines.  We'll use a shorthand term
41  * "lnl" (Lustre NetLink) for this interface name for all arches, even though
42  * an implemtation may not use NetLink.
43  * The definitions below are used in the kernel and userspace.
44  *
45  */
46
47 #ifndef __LIBCFS_KERNELCOMM_H__
48 #define __LIBCFS_KERNELCOMM_H__
49
50 #ifndef __LIBCFS_LIBCFS_H__
51 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
52 #endif
53
54 /* LNL message header.
55  * All current and future LNL messages should use this header.
56  * To avoid having to include Lustre headers from libcfs, define this here.
57  */
58 struct lnl_hdr {
59         __u16 lnl_magic;
60         __u8  lnl_transport;  /* Each new Lustre feature should use a different
61                                  transport */
62         __u8  lnl_flags;
63         __u16 lnl_msgtype;    /* Message type or opcode, transport-specific */
64         __u16 lnl_msglen;
65 } __attribute__((aligned(sizeof(__u64))));
66
67 #define LNL_MAGIC  0x191C /*Lustre9etLinC */
68 #define LNL_FL_BLOCK 0x01   /* Wait for send */
69
70 /* lnl_msgtype values are defined in each transport */
71 enum lnl_transport_type {
72         LNL_TRANSPORT_GENERIC   = 1,
73         LNL_TRANSPORT_HSM       = 2,
74         LNL_TRANSPORT_CHANGELOG = 3,
75 };
76
77 enum lnl_generic_message_type {
78         LNL_MSG_SHUTDOWN = 1,
79 };
80
81 /* LNL Broadcast Groups. This determines which userspace process hears which
82  * messages.  Mutliple transports may be used within a group, or multiple
83  * groups may use the same transport.  Broadcast
84  * groups need not be used if e.g. a PID is specified instead;
85  * use group 0 to signify unicast.
86  */
87 #define LNL_GRP_HSM           0x02
88 #define LNL_GRP_CNT              2
89
90
91 #if defined(HAVE_NETLINK) && defined (__KERNEL__)
92 extern int libcfs_klnl_start(int transport);
93 extern int libcfs_klnl_stop(int transport, int group);
94 extern int libcfs_klnl_msg_put(int pid, int group, void *payload);
95 #else
96 static inline int libcfs_klnl_start(int transport) {
97         return -ENOSYS;
98 }
99 static inline int libcfs_klnl_stop(int transport, int group) {
100         return 0;
101 }
102 static inline int libcfs_klnl_msg_put(int pid, int group, void *payload) {
103         return -ENOSYS;
104 }
105 #endif
106
107 /*
108  * NetLink socket number, see include/linux/netlink.h
109  * All LNL users share a single netlink socket.  This actually is NetLink
110  * specific, but is not to be used outside of the Linux implementation
111  * (linux-kernelcomm.c and posix-kernelcomm.c).
112  */
113 #define LNL_SOCKET 26
114
115
116 #endif /* __LIBCFS_KERNELCOMM_H__ */
117