Update the syslink documentation. A number of major design changes have
[games.git] / lib / libc / sys / syslink.2
1 .\" Copyright (c) 2007 The DragonFly Project.  All rights reserved.
2 .\"
3 .\" This code is derived from software contributed to The DragonFly Project
4 .\" by Matthew Dillon <dillon@backplane.com>
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\"
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in
14 .\"    the documentation and/or other materials provided with the
15 .\"    distribution.
16 .\" 3. Neither the name of The DragonFly Project nor the names of its
17 .\"    contributors may be used to endorse or promote products derived
18 .\"    from this software without specific, prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
24 .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 .\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" SUCH DAMAGE.
32 .\"
33 .\" $DragonFly: src/lib/libc/sys/syslink.2,v 1.3 2007/03/24 18:53:57 dillon Exp $
34 .\"
35 .Dd March 13, 2007
36 .Dt SYSLINK 2
37 .Os
38 .Sh NAME
39 .Nm syslink
40 .Nd low level connect to the cluster mesh
41 .Sh LIBRARY
42 .Lb libc
43 .Sh SYNOPSIS
44 .In sys/syslink.h
45 .Ft int
46 .Fn syslink "int fd" "int flags" "sysid_t routenode"
47 .Sh DESCRIPTION
48 The
49 .Fn syslink
50 function establishes a link to a kernel-implemented syslink route node
51 as specified by
52 .Fa routenode .
53 If a file descriptor of -1 is specified, a file descriptor representing
54 a direct connection to the specified route node will be allocated and
55 returned.
56 If a file descriptor is specified, it will be connected to the specified
57 route node via full-duplex communication and kernel threads will be
58 created to shuttle data between the descriptor and the route node.  The
59 kernel may optimize and shortcut this operation.
60 .Pp
61 It is also perfectly legal to allocate two route nodes and then connect them
62 together by passing the file descriptor returned by the first
63 .Fn syslink
64 call to the second
65 .Fn syslink
66 call.  It is legal (and usually necessary) to obtain multiple descriptors to
67 the same kernel-managed syslink route node.
68 .Pp
69 The syslink protocol revolves around 64 bit system ids using the
70 .Ft sysid_t
71 type.  A sysid can represent one of three entities:  A session identifier,
72 a logical identifier, or a physical identifier.
73 Session ids are synthesized by machine nodes and used to
74 uniquely identify a communications session between two entities in a way
75 that prevents any possible duplication or confusion in the face of a
76 constantly changing mesh, migration of logical elements, and other activities.
77 Logical ids are persistent entities which uniquely identify resources.
78 Examples of resources include filesystems, hard drive partitions, devices,
79 VM spaces, memory, cpus, and so forth.  The logical id migrates with the
80 resource, meaning that you can physically move a hard drive from one part
81 of the mesh to another and the mesh will automatically figure out the
82 new location.  New logical identifiers are also typically synthesized
83 entities.  Physical ids are dynamically propogated through the mesh from
84 seed nodes and used to route messages.  Any given node in the mesh may be
85 addressable via multiple physical ids, each representing a different path
86 to the node.
87 .Pp
88 For example, a particular filesystem mount will have a persistent logical
89 sysid, a separate session id for every entity connecting to it, and one or
90 more dynamic (changable) physical sysids depending on the mesh topology.
91 .Sh SYSLINK PROTOCOL - PHYSICAL SYSIDS
92 The Syslink protocol is used to glue the cluster mesh together.  It is
93 based on the concept of (mostly) reliable packets and buffered streams.
94 Adding a new node to the mesh is as simple as obtaining a stream connection
95 to any node already in the mesh, or tying into a packet switch with UDP.
96 .Pp
97 Physical sysids are propogated from seed nodes in the mesh.  There must be
98 at least one seed node and there are usually on the order of 2-4.  Seed
99 nodes are usually located at key points in the cluster topology.  A seed
100 node has a statically assigned physical space.  Propogation consists of
101 chopping a number of bits off the space and assigning an address value 
102 for each connecting entity, then propogating the space through the connecting
103 entity.  The connecting entity chops more bits off the space for its own
104 connecting entities and continues propogating the address space.  Loops in
105 the graph are trivially detected simply by observing the number of free bits
106 in the propogated space.
107 .Pp
108 Physical sysid propogation occurs continuously and allows the mesh to
109 dynamically adapt to changes in the topology within a few seconds.
110 Due to the nature of the propogation of the space, each physical sysid
111 can be used to trivially route messages between two entities.
112 Link-layer communication (that is, communication between directly adjacent
113 nodes) can occur independantly of physical sysid space propogation.
114 Communication with seed nodes is also trivial, since seed nodes represent
115 static physical sysids.
116 The physical sysid of a node can change at any time, sometimes radically.
117 Session ids are used to maintain sanity in a changing topology.
118 .Sh SYSLINK PROTOCOL - SESSION SYSIDS
119 Session sysids are used to uniquely identify a communications link between
120 two entities in the mesh.  Session sysids are synthesized by individual
121 machines and maintained by the two route nodes at the two end points for
122 any particular communications session.  For example, if a device A wishes to
123 communicate with a filesystem B, and device A connects to route node Ra
124 and filesystem B connects to route node Rb, then Ra and Rb are responsible
125 for translating the session sysid in the message to physical sysids for
126 routing the message.  The end points simply use the session id.  Creating
127 the 'connection'... that is, allocating the session id in the first place,
128 is similar to an 'open' command.  The entity issuing the open talks to its
129 immediate route node (A would talk to Ra) to initiate the session and obtain
130 the session id.
131 .Pp
132 Session sysids are forever unique.  A communications session can survive
133 migration and topological changes, even if the route node changes.  When
134 a topological change is detected, the session must be re-trained, which is
135 a simple protocol from the point of view of leaf and route nodes.
136 Route nodes manage timeouts, retries, and error handling for the sessions
137 under their care, greatly reducing the protocol complexity from the viewpoint
138 of a leaf node (e.g. filesystem, device, whatever).  Leaf nodes (connected
139 to the route node via a stream) need only detect disconnections of the
140 stream.
141 .Pp
142 Establishment of a new session or retraining an existing session is usually
143 based on the logical sysid for the two entities involved.  That is, sessions
144 are created between entities defined by a logical sysid for each entity.
145 The logical sysid is the ultimate rendezvous, the session sysid identifies
146 a session or transaction, the physical sysid routes the message.
147 .Sh SYSLINK PROTOCOL - LOGICAL SYSIDS
148 Logical sysids are forever-unique, persistent entities which represent
149 the ultimate rendezvous identifier.  When you label a new disk, a unique
150 logical sysid will be assigned to that label which allows the disk to be
151 properly identified no matter where it resides in the cluster.  
152 A logical sysid is associated with an ascii name and a type for
153 identification purposes.  For example, when you label a new disk it will
154 be given a unique 64 bit logical sysid and you must also supply a name,
155 such as 'MYDISK01'.  The disk can then be located by its logical sysid or
156 by its name and type.
157 Resources can be broken up into smaller pieces and those pieces can
158 also be assigned logical sysids.  For example, an ANVIL disk partition can
159 have its own logical sysid and name independant of the one assigned to the
160 label.
161 .Pp
162 Logical sysids are typically synthesized by individual machines without
163 mesh involvement.  Synthesized logical sysids are usually based on a
164 hash of an interface MAC address combined with a timestamp and iterator.
165 When making resources available to a named cluster, the logical sysids
166 of the resources may be translated to cluster-friendly logical sysids
167 as part of the setup, but intervention (in the form of translation) is only
168 needed if an actual conflict occurs.  An external mechanism unrelated to
169 the cluster itself detects conflicts -- usually a database of some sort
170 which associates a much larger unique id made up of a full domain name and
171 timestamp with the hash.  Typically 24 Machine-unique bits are reserved out
172 of the 64 bit sysid, leaving 40 bits.  This allows several hundred to
173 several thousand new unique, logical sysids to be allocated per second.
174 The actual number is usually far smaller (how often do you create a new
175 disklabel?).  This may seem confusing but it is really nothing more then
176 a simple translation layer that allows unrelated machine resources (e.g.
177 owned by different people) to be associated with the same cluster.
178 Only the machine-unique bits may need to be translated.
179 .Sh SYSLINK PROTOCOL - PROPOGATION OF PHYSICAL SYSID SPACE
180 Assignment of physical sysid space is simple.  The seed nodes take their
181 statically assigned sysid space (specified by a 64 bit CIDR block), cut out
182 enough bits to handle the number of connections that need to be supported,
183 and then dole out a subnet to each connectee.  If a connectee is a route node
184 it is then able to cut up the subnet CIDR block and dole out subnets to
185 nodes that connect to it.  Leaf nodes have fixed SYSID space requirements,
186 typically 10 bits.  If a leaf node is handed a 24 bit sysid space it will
187 still use only 10 bits of it.  A leaf node handed a sysid space below its
188 minimum requirement simply ignores that space.
189 .Pp
190 Eventually every seed node propogates its physical sysid space to every other
191 node in the mesh.  If a mesh has four seed nodes, then every node in the mesh
192 will wind up with at least four physical SYSID spaces.
193 Nodes may obtain additional physical SYSID assignments due to loops
194 in the graph.  For example, if you create a triangle between nodes A, B,
195 and C, with B as the seed node, then SYSID will propogate B->C->A->B and
196 B->A->C->B and node A will wind up with two physical SYSID assignments (and
197 node B will have four) even though there was only one seed node.
198 Physical SYSID assignments represent routing paths.
199 Because the mesh is potentially too large to store the full graph
200 in memory, the SYSLINK protocol only requires that the four largest SYSID
201 spaces for any given seed be retained by every node.  This creates a
202 self-healing mesh with reasonable, but not ultimate redundancy.
203 .Pp
204 Only a limited number of hops are supported in the mesh due to the
205 limitations of the 64 bit ID space and the need to be able to route
206 messages trivially using a single 64 bit physical id - without having to
207 retain a route table for the whole mesh in each route node.  Very large
208 meshes require some attention to the design of the topology to retain
209 reasonable redundancy.
210 For example, if you are trying to create an internet-wide mesh to handle
211 a massively distributed problem which requires low data bandwidths,
212 you might implement a couple of very large CIDR distribution blocks
213 for people to connect to via TCP streams.
214 .Pp
215 Once physical SYSID space is assigned (and remember, the physical SYSID
216 space can change on the fly as nodes go up and down), messages may be sent
217 from one physical SYSID to another, or broadcast across the entire mesh.
218 Only messages to immediate neighbors are guaranteed to be reliable, but
219 for the cluster to operate efficiently packet loss is not tolerated.
220 Message delivery failures must be almost solely due to losses which occur
221 when the topology changes (due to a node going up or down).
222 .Sh SYSLINK PROTOCOL - LOGICAL AND SESSION SYSIDS, ALLOCATION
223 Logical and session sysids are synthesized based on a unique per-machine
224 mesh id (usually a hash of an interface MAC address), plus timestamp and
225 iterator.  As long as the machine's system time is reasonably accurate (and
226 it had better be), the uniqueness will be maintained across reboots and other
227 spurious events.
228 .Sh SYSLINK PROTOCOL - LOGICAL AND SESSION SYSIDS, REGISTRATION AND RESOLUTION
229 A leaf node must register the logical sysids it wishes to make available to
230 the cluster with the route node it connects to.  These registrations allow
231 the route node to resolve lookup requests from the cluster to that particular
232 leaf node.  By default, lookup requests are broadcast to all route nodes.
233 Bandwidth can be reduced by allowing route nodes near the leafs of the
234 cluster mesh to propogate the registration(s) to a tighter set of route
235 nodes within the cluster, greatly reducing the cost of doing a logical sysid
236 lookup.
237 .Sh SYSLINK PROTOCOL - MESSAGE ROUTING
238 Session sysids are the 'open/connected' abstraction for leaf entities and
239 are maintained by route nodes, allowing leaf nodes to construct syslink
240 messages using only the session sysid and a direction bit.  A route node
241 can lose track of a session sysid... for example, a leaf node might migrate
242 to another part of the cluster or might have to use a communications path
243 via a different route node due to a failure or a change in the topology.  If
244 a route node does not recognize the session id of a syslink message, it
245 replies with a RETRAIN request to the leaf node.  The leaf node then retrains
246 the session id by providing all the information required for the route node
247 to reconstruct the connection (typically the originating and target logical
248 sysid).  The routing node not only caches the logical sysid information, it
249 is also responsible for looking up and caching physical sysids to actually
250 route message(s).
251 .Pp
252 This may seem complex but it all comes down to a very simple messaging
253 format and protocol.  The retraining protocol also serves to validate 
254 communications links between entities and to allow massive changes in
255 mesh topology to occur without disrupting the cluster.  For example, if
256 the physical sysid of a node changes it will set off a chain of events
257 at the route nodes due to the now-mismatched physical sysid and session
258 sysid.  A message winds up being routed to the wrong target which detects
259 the misrouting due to the unknown session id.  The error feeds back to
260 the route node which can then clear its physical sysid cache and relookup
261 the route.
262 .Pp
263 Syslink messages are transactional in nature and it is possible for a single
264 transaction to be made up of multiple messages... for example, to break down
265 a large buffer into smaller pieces for the purposes of transmission over the
266 mesh.  The syslink protocol imposes fairly severe limitations on transactional
267 messages and sizes... syslink messages are not meant to abstract very large
268 multi-megabyte I/O operations but instead are meant to provide a reliable
269 communications abstraction for smaller messages and buffers.
270 A transaction may contain no more than 32 individual messages, allowing
271 the route node to use a simple bitmap to track messages which may arrive
272 out of order.
273 Any given session may only have one transaction pending at a time... parallel
274 transactions are implemented by creating multiple sessions between the same
275 two entities.
276 .Pp
277 The messages making up a transaction can arrive out of order and will be
278 collected by the target until all messages are present.  The originator
279 must hold onto all messages it sends (so it can re-send if requested by
280 the route node), until it has the complete response.
281 The route node for a leaf is responsible for weeding out duplicate messages,
282 monitoring transactions, and handling timeouts (returning a retry indication
283 to the leaf).
284 Route nodes are not responsible for buffering messages.  It is the leaf nodes
285 that must buffer and collect the messages, the route nodes only track the
286 transaction.
287 If the physical sysid becomes invalid the route node is typically responsible
288 for locating a new physical sysid and returning a transaction abort to the
289 leaf.
290 .Pp
291 Message transactions are uniquely identified by the (sessionid, msgid) fields
292 in the syslink message.  Bits in the msgid field identify whether a request
293 is being sent from the originator or target (determined by who initiated the
294 original 'connection'), and whether the message is a command message or a
295 reply message.
296 Either side can initiate a transaction over an established session, which
297 means that there may be a transaction going in both directions at the same
298 time, each with request and reply messages.  Transactions initiated by
299 the target are usually used for event and blocking/unblocking notifications.
300 .Pp
301 The SYSLINK protocol is not intended to take the place of a reliable link
302 level protocol such as TCP and mesh links should only use UDP when packet
303 delivery can be virtually guarenteed (such as when operating over switched
304 ethernet).  UDP-based syslinks may still buffer multiple messages within
305 the limitations of the UDP packet.
306 .Pp
307 The SYSLINK protocol is not intended to provide quorum guarentees.  Quorum
308 protocols operate over SYSLINK, but are not implemented by SYSLINK.
309 .Sh SYSLINK PROTOCOL - MESSAGE BUFFERING
310 Syslinks which operate over buffered connections where messages may be
311 sent or received in bulk must adhere to certain alignment and cross-over
312 requirements to allow buffers to be implemented as FIFOs.  The message length
313 field in a syslink message is not particular aligned, but syslink messages
314 themselves must always be 16-byte aligned, creating small amounts of dead
315 space in the buffer (and the data stream).  Additionally, the physical
316 sysid propogation protocol also propogates a FIFO cross-over size, which is
317 always a power of 2.  Typical values range from 64KB to 1024KB.  Messages
318 received on a stream can be written into a buffer in FIFO fashion.  No single
319 message may straddle the end of the FIFO's physical buffer (that is, cross
320 back over to the beginning).  All transmitters must adhere to the FIFO
321 size supplied in the initial message traffic by generating a PAD message
322 when necessary.  Larger FIFO sizes are usually better since they result
323 in smaller PADs.  I/O transactions containing data are typically broken up
324 into smaller messages not only to accomodate limitations in transport
325 protocols (such as UDP), but also to reduce the dead space created by PADs.
326 On the bright side, these requirements allow very optimal hardware and
327 software buffering of syslink message traffic.
328 .Sh BLOCKING TRANSACTIONS
329 Certain operations can block.  That is, the target may not be able to
330 immediately complete the requested transaction.  When a transaction blocks
331 the target is responsible for returning a keep-alive blocking indication
332 to the originator to prevent the originator from retrying or aborting
333 the transaction.  Keep-alives can be directly handled by the route node
334 connected to the target (since it knows if the leaf disconnects),
335 simplifying leaf operation.  A route node will very occassionally do a sanity
336 check request to the leaf (perhaps once a minute) to verify that
337 transactions blocked for a long time are still known to the leaf.
338 .Pp
339 Blocking indications are special response messages that set the
340 blocked-operation bit in the sequence field and do not set the
341 end-transaction bit.
342 .Sh TRANSACTION ABORTS
343 A transaction can be aborted.  Normally aborted transactions still
344 required an acknowledgement (since the abort may race completion).
345 If the target completes the transaction before receiving the abort
346 request, it is as if the abort never occured.
347 .Sh ASYNCHRONOUS PUSH TRANSACTIONS
348 Most syslink transactions require an acknowledgement to terminate the
349 transaction.  The acknowledgement is typically a single message in the
350 return direction with both the start and stop bits set.  Multi-message
351 responses are of course possible, such as when the transaction is
352 implementing an I/O read operation.
353 .Pp
354 Certain syslink transactions do not require an acknowledgement and do not
355 implement the retry or timeout protocols.  Such transactions are typically
356 cache-push operations which are used to optimize operation of the cluster
357 by allowing a node to asynchronously push data to places where it thinks
358 it will be needed immediately.  The most commmon use of this sort of
359 operation is the read-ahead optimization.  When one node performs a read
360 transaction with another node, and the target node is capable of read-ahead
361 and detemines that read-ahead is useful, the target node can initiate the
362 read-ahead and push the data to the originating node in a separate
363 asyncnronous transaction.  Read-aheads are typically not directly adjacent
364 to the read that just occured in order to allow the originator to initiate
365 the next synchronous transaction without it crossing paths with the
366 asynchronous read-ahead push (resulting in the same data being returned to
367 the originator twice).
368 .Sh OPERATING AS A ROUTE NODE
369 Most userland applications using syslink will operate as leaf nodes, but
370 there is nothing preventing you from oprating as a route node.  Operating
371 as a route node requires implementing all route node requirements including
372 the handling of logical sysid registrations and the tracking of transactions
373 initiated by nodes that directly connect to you.  In fact, sysid seeding
374 nodes are user processes which operate as degenerate route nodes.
375 .Sh RETURN VALUES
376 The value -1 is returned if an error occurs in either call.
377 The external variable
378 .Va errno
379 indicates the cause of the error.
380 If a descriptor is supplied and the system call is successful, 0 is
381 returned.  If a descriptor is not supplied and the system call is successful,
382 a descriptor is returned representing a direct connection to the mesh's
383 route node.
384 .Sh SEE ALSO
385 .Sh HISTORY
386 The
387 .Fn syslink
388 function first appeared in
389 .Dx 1.9 .