Probably the last change to the syslink() system call. Allow a generic
[dragonfly.git] / sys / sys / syslink.h
blob1695b1e8fbaaad3bb38ad27787fb987fcceef03e
1 /*
2 * Copyright (c) 2004-2007 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * $DragonFly: src/sys/sys/syslink.h,v 1.5 2007/04/16 17:40:16 dillon Exp $
38 * The syslink infrastructure implements an optimized RPC mechanism across a
39 * communications link. RPC functions are grouped together into larger
40 * protocols. Prototypes are typically associated with system structures
41 * but do not have to be.
43 * syslink - Implements a communications end-point and protocol. A
44 * syslink is typically directly embedded in a related
45 * structure.
47 * syslink_proto- Specifies a set of RPC functions.
49 * syslink_desc - Specifies a single RPC function within a protocol.
52 #ifndef _SYS_SYSLINK_H_
53 #define _SYS_SYSLINK_H_
55 #ifndef _SYS_TYPES_H_
56 #include <sys/types.h>
57 #endif
58 #ifndef _SYS_TREE_H_
59 #include <sys/tree.h>
60 #endif
61 #ifndef _SYS_SOCKET_H_
62 #include <sys/socket.h>
63 #endif
66 * SYSIDs are 64 bit entities and come in two varieties. Physical SYSIDs
67 * are used to efficiently route messages across the mesh, while Logical
68 * SYSIDs are persistently assigned identifiers representing specific devices
69 * or specific media or named filesystems. That is, the logical SYSID
70 * assigned to a filesystem or ANVIL partition can be stored in that
71 * filesystem's superblock and allows the filesystem to migrate or
72 * be multi-homed (have multiple physical SYSIDs representing the same
73 * logical entity).
75 * Physical SYSIDs can be ever-changing, and any given logical SYSID could
76 * in fact have multiple physical SYSIDs associated with it. The mesh is
77 * self-healing and the combination of the logical and physical sysid
78 * basically validates the message at the target and determines whether
79 * the physical SYSID must be recalculated (looked up again) or not.
81 typedef u_int64_t sysid_t;
83 /***************************************************************************
84 * PROTOCOL API/ABI *
85 ***************************************************************************
87 * These structures implement the programming interface for end-points and
88 * RPC calls.
91 struct syslink;
92 struct syslink_ops;
93 struct syslink_proto;
94 struct syslink_transport;
95 struct syslink_desc;
96 struct syslink_generic_args;
98 typedef int (*syslink_func_t)(struct syslink_generic_args *);
101 * Commands for the syslink system call.
103 * CREATE: Create a new syslink route node with the route node sysid
104 * and label information specified in the passed info structure.
105 * 0 on success, -1 on failure or if the route node already
106 * exists.
108 * The info structure must also contain the number of bits of
109 * address space you wish this route node to use.
111 * DESTROY: Destroy the existing syslink route node with the route node
112 * sysid specified in the passed info structure.
113 * 0 on success, -1 on failure.
115 * LOCATE: Locate the first syslink route node with a sysid greater or
116 * equal to the sysid specified in the passed info structure.
117 * The info structure will be loaded on success and the linkid
118 * field will also be cleared.
120 * To scan route nodes, start by specifying a sysid 0. On
121 * success, increment the sysid in the info structure and loop.
123 * You can also use the contents of the info structure to
124 * initiate a scan of links within the route node via the FIND
125 * command. The sysid will remain unchanged through the scan
126 * and on completion you can increment it and loop up to
127 * the next LOCATE.
129 * ADD: Add a link to the route node specified in the info structure.
130 * The route node must exist and must contain sufficient
131 * address space to handle the new link. If associating a file
132 * descriptor, 0 is returned on success and -1 on failure.
133 * If obtaining a direct syslink file descriptor, the new
134 * descriptor is returned on success or -1 on failure.
136 * On return, the linkid in the info structure is filled in and
137 * other adjustments may also have been made.
139 * The info structure must contain the number of bits of
140 * address space required by the link. If 0 is specified,
141 * a direct stream or connected socket is expected. If
142 * non-zero, a switch is assumed (typically a switched UDP
143 * socket). An all 0's address is reserved and an all 1's
144 * address implies a broadcast. All other addresses imply
145 * single targets within the switched infrastructure.
147 * FLAGS SUPPORTED:
149 * SENDTO This allows you to directly associate a
150 * UDP socket and subnet with a syslink route
151 * node. To use this option the info structure
152 * must contain a sockaddr representing the
153 * broadcast address. The low bits are adjusted
154 * based on the size of the subnet (as
155 * specified with PHYSBITS) to forward messages.
156 * If not specified, write() is used and the
157 * target is responsible for any switch
158 * demultiplexing.
160 * PACKET Indicates that messages are packetized.
161 * syslink will aggregate multiple syslink
162 * messages into a single packet if possible,
163 * but will not exceed 16384 bytes per packet
164 * and will not attempt to pad messages to
165 * align them for FIFO debuffering.
167 * REM: Disassociate a link using the route node and linkid
168 * specified in the info structure.
170 * The syslink route node will close() the related descriptor
171 * (or cause an EOF to occur for any direct syslink descriptor).
173 * FIND: Locate the first linkid greater or equal to the linkid
174 * in the passed info structure for the route node sysid
175 * specified in the info structure, and fill in the rest of the
176 * structure as appropriate.
178 * To locate the first link for any given route sysid, set
179 * linkid to 0. To scan available links, increment the
180 * returned linkid before looping.
183 #define SYSLINK_CMD_CREATE 0x00000001 /* create route node */
184 #define SYSLINK_CMD_DESTROY 0x00000002 /* destroy route node */
185 #define SYSLINK_CMD_LOCATE 0x00000003 /* locate first route node */
186 #define SYSLINK_CMD_ADD 0x00000004 /* add link */
187 #define SYSLINK_CMD_REM 0x00000005 /* remove link */
188 #define SYSLINK_CMD_FIND 0x00000006 /* locate link info */
190 #define SYSLINK_LABEL_SIZE 32
191 #define SYSLINK_ROUTER_MAXBITS 20
193 * syslink_info structure
195 * This structure contains information about a syslink route node or
196 * linkage.
198 struct syslink_info {
199 sysid_t sysid; /* route node sysid */
200 int linkid; /* linkid (base physical address) */
201 int bits; /* physical address bits if switched */
202 int flags; /* message control/switch flags */
203 char label[SYSLINK_LABEL_SIZE]; /* symbolic name */
204 char reserved[32];
205 union {
206 struct sockaddr sa; /* required for SLIF_SENDTO */
207 } u;
210 #define SLIF_PACKET 0x0001 /* packetized, else stream */
211 #define SLIF_SENDTO 0x0002 /* use sendto() */
212 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
213 #define SLIF_DESTROYED 0x4000
214 #define SLIF_ERROR 0x8000
215 #endif
217 #define SLIF_USERFLAGS (SLIF_PACKET|SLIF_SENDTO)
221 * A syslink structure represents an end-point for communications. System
222 * structures such as vnodes are typically associated with end-points and
223 * usually embed a syslink structure. There is typically one master
224 * structure (sl_remote_id == 0) and any number of slave structures at
225 * remote locations (sl_remote_id on slaves point to master).
227 * A ref counter is integrated into the structure and used by SYSLINK to
228 * keep track of sysid references sent to remote targets. This counter
229 * may also be used by the governing structure (e.g. vnode) so long as
230 * the SYSLINK API is used to manipulate it.
232 * An operations vector implements the ABI for the numerous functions
233 * associated with the system structure. E.G. VOPs for vnodes. The
234 * ops structure also references the transport and protocol layers. Using
235 * vnodes as an example, the ops structure would be replicated from a
236 * template on a per-mount basis.
238 struct syslink {
239 sysid_t sl_source;
240 sysid_t sl_target;
241 int sl_refs; /* track references */
242 struct syslink_ops *sl_ops; /* operations vector */
246 * The syslink_ops structure is typically embedded as part of a larger system
247 * structure. It conatins a reference to the transport layer (if any),
248 * protocol, and a structural offset range specifying the function vectors
249 * in the larger system structure.
251 * For example, vnode operations (VOPs) embed this structure in the vop_ops
252 * structure.
254 * The syslink_ops structure may be replaced as necessary. The VFS subsystem
255 * typically replicates syslink_ops on a per-mount basis and stores a pointer
256 * to the mount point in the larger system structure (vop_ops).
258 struct syslink_ops {
259 struct syslink_proto *proto;
260 void *transport; /* FUTURE USE (transport layer) */
261 int beg_offset;
262 int end_offset;
266 * The syslink_desc structure describes a function vector in the protocol.
267 * This structure may be extended by the protocol to contain additional
268 * information.
270 struct syslink_desc {
271 int sd_offset; /* offset into ops structure */
272 const char *sd_name; /* name for debugging */
276 * The syslink_proto structure describes a protocol. The structure contains
277 * templates for the various ops structures required to implement the
278 * protocol.
280 struct syslink_proto {
281 const char *sp_name; /* identifying name */
282 int sp_flags;
283 int sp_opssize; /* structure embedding syslink_ops */
284 struct syslink_ops *sp_call_encode; /* encode call */
285 struct syslink_ops *sp_call_decode; /* decode call */
286 struct syslink_ops *sp_reply_encode; /* encode reply */
287 struct syslink_ops *sp_reply_decode; /* decode reply */
288 struct syslink_ops *sp_ops; /* direct ABI calls */
291 #define SPF_ALLOCATED 0x00000001
294 * The syslink_generic_args structure contains the base data required in
295 * the arguments structure passed to any given ops function. This structure
296 * is typically extended with the actual call arguments.
298 struct syslink_generic_args {
299 struct syslink_desc *a_desc; /* ABI method description */
300 struct syslink *a_syslink; /* original syslink */
301 /* extend arguments */
304 typedef struct syslink *syslink_t;
305 typedef struct syslink_ops *syslink_ops_t;
306 typedef struct syslink_desc *syslink_desc_t;
307 typedef struct syslink_proto *syslink_proto_t;
308 typedef struct syslink_generic_args *syslink_generic_args_t;
310 #if !defined(_KERNEL)
311 int syslink(int, int, sysid_t, void *, size_t *);
312 #endif
314 #endif