Introduce sys/syslink.h, the beginnings of a VOP-compatible RPC-like
[dragonfly.git] / sys / sys / syslink.h
1 /*
2  * Copyright (c) 2004-2006 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:
10  * 
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.
20  * 
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.
33  *
34  * $DragonFly: src/sys/sys/syslink.h,v 1.1 2006/07/19 06:08:07 dillon Exp $
35  */
36
37 /*
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.
42  *
43  * syslink      - Implements a communications end-point and protocol.  A
44  *                syslink is typically directly embedded in a related
45  *                structure.
46  *
47  * syslink_proto- Specifies a set of RPC functions.
48  *
49  * syslink_desc - Specifies a single RPC function within a protocol.
50  */
51
52 #ifndef _SYS_SYSLINK_H_
53 #define _SYS_SYSLINK_H_
54
55 #ifndef _SYS_TYPES_H_
56 #include <sys/types.h>
57 #endif
58
59 /*
60  * SYSIDs are 64 bit entities.
61  */
62 typedef u_int64_t       sysid_t;
63
64 /***************************************************************************
65  *                              PROTOCOL API/ABI                           *
66  ***************************************************************************
67  *
68  * These structures implement the programming interface for end-points and
69  * RPC calls.
70  */
71
72 struct syslink;
73 struct syslink_ops;
74 struct syslink_proto;
75 struct syslink_transport;
76 struct syslink_desc;
77 struct syslink_generic_args;
78
79 typedef int (*syslink_func_t)(struct syslink_generic_args *);
80
81 /*
82  * A syslink structure represents an end-point for communications.  System
83  * structures such as vnodes are typically associated with end-points and
84  * usually embed a syslink structure.  There is typically one master
85  * structure (sl_remote_id == 0) and any number of slave structures at
86  * remote locations (sl_remote_id on slaves point to master).
87  *
88  * A ref counter is integrated into the structure and used by SYSLINK to
89  * keep track of sysid references sent to remote targets.  This counter
90  * may also be used by the governing structure (e.g. vnode) so long as
91  * the SYSLINK API is used to manipulate it.
92  *
93  * An operations vector implements the ABI for the numerous functions
94  * associated with the system structure.  E.G. VOPs for vnodes.  The
95  * ops structure also references the transport and protocol layers.  Using
96  * vnodes as an example, the ops structure would be replicated from a
97  * template on a per-mount basis.
98  */
99 struct syslink {
100         sysid_t         sl_sysid;       /* syslink id of this end-point */
101         sysid_t         sl_remote_id;   /* syslink id of remote end-point */
102         int             sl_refs;        /* track references */
103         struct syslink_ops *sl_ops;     /* operations vector */
104 };
105
106 /*
107  * The syslink_ops structure is typically embedded as part of a larger system
108  * structure.  It conatins a reference to the transport layer (if any),
109  * protocol, and a structural offset range specifying the function vectors
110  * in the larger system structure.
111  *
112  * For example, vnode operations (VOPs) embed this structure in the vop_ops
113  * structure.
114  *
115  * The syslink_ops structure may be replaced as necessary.  The VFS subsystem
116  * typically replicates syslink_ops on a per-mount basis and stores a pointer
117  * to the mount point in the larger system structure (vop_ops).
118  */
119 struct syslink_ops {
120         struct syslink_proto *proto;
121         void *transport;        /* FUTURE USE (transport layer) */
122         int beg_offset;
123         int end_offset;
124 };
125
126 /*
127  * The syslink_desc structure describes a function vector in the protocol.
128  * This structure may be extended by the protocol to contain additional
129  * information.
130  */
131 struct syslink_desc {
132         int sd_offset;          /* offset into ops structure */
133         const char *sd_name;    /* name for debugging */
134 };
135
136 /*
137  * The syslink_proto structure describes a protocol.  The structure contains
138  * templates for the various ops structures required to implement the
139  * protocol.
140  */
141 struct syslink_proto {
142         const char      *sp_name;       /* identifying name */
143         int             sp_flags;
144         int             sp_opssize;     /* structure embedding syslink_ops */
145         struct syslink_ops *sp_call_encode;     /* encode call */
146         struct syslink_ops *sp_call_decode;     /* decode call */
147         struct syslink_ops *sp_reply_encode;    /* encode reply */
148         struct syslink_ops *sp_reply_decode;    /* decode reply */
149         struct syslink_ops *sp_ops;             /* direct ABI calls */
150 };
151
152 #define SPF_ALLOCATED   0x00000001
153
154 /*
155  * The syslink_generic_args structure contains the base data required in
156  * the arguments structure passed to any given ops function.  This structure
157  * is typically extended with the actual call arguments.
158  */
159 struct syslink_generic_args {
160         struct syslink_desc     *a_desc;        /* ABI method description */
161         struct syslink          *a_syslink;     /* original syslink */
162         /* extend arguments */
163 };
164
165 typedef struct syslink *syslink_t;
166 typedef struct syslink_ops *syslink_ops_t;
167 typedef struct syslink_desc *syslink_desc_t;
168 typedef struct syslink_proto *syslink_proto_t;
169 typedef struct syslink_generic_args *syslink_generic_args_t;
170
171 #endif