shim_ipc_ns.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* Copyright (C) 2014 Stony Brook University
  4. This file is part of Graphene Library OS.
  5. Graphene Library OS is free software: you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. Graphene Library OS is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /*
  16. * shim_ipc_ns.h
  17. *
  18. * Definitions of types and functions for IPC namespace bookkeeping.
  19. */
  20. #ifndef __SHIM_IPC_NS_H__
  21. #define __SHIM_IPC_NS_H__
  22. #include <shim_types.h>
  23. #include <shim_internal.h>
  24. #define IPC_NS_CALLBACKS(ns) \
  25. /* FINDNS */ &ipc_##ns##_findns_callback, \
  26. /* TELLNS */ &ipc_##ns##_tellns_callback, \
  27. /* LEASE */ &ipc_##ns##_lease_callback, \
  28. /* OFFER */ &ipc_##ns##_offer_callback, \
  29. /* RENEW */ &ipc_##ns##_renew_callback, \
  30. /* REVOKE */ &ipc_##ns##_revoke_callback, \
  31. /* SUBLEASE */ &ipc_##ns##_sublease_callback, \
  32. /* QUERY */ &ipc_##ns##_query_callback, \
  33. /* QUERYALL */ &ipc_##ns##_queryall_callback, \
  34. /* ANSWER */ &ipc_##ns##_answer_callback,
  35. #define IPC_NS_KEY_CALLBACKS(ns) \
  36. /* FINDKEY */ &ipc_##ns##_findkey_callback, \
  37. /* TELLKEY */ &ipc_##ns##_tellkey_callback,
  38. #define NS_PORT_CONSTS(n) \
  39. n##CLT, \
  40. n##LDR, \
  41. n##CON, \
  42. n##OWN,
  43. #define NS_PORT_TYPES(n) \
  44. IPC_PORT_##n##CLT = 1<<n##CLT, \
  45. IPC_PORT_##n##LDR = 1<<n##LDR, \
  46. IPC_PORT_##n##CON = 1<<n##CON, \
  47. IPC_PORT_##n##OWN = 1<<n##OWN,
  48. struct ipc_ns_offered {
  49. IDTYPE base, size;
  50. LEASETYPE lease;
  51. unsigned int owner_offset;
  52. } __attribute__((packed));
  53. struct ipc_ns_client {
  54. IDTYPE vmid;
  55. char uri[1];
  56. } __attribute__((packed));
  57. #endif /* __SHIM_IPC_NS_H__ */
  58. #define NS_SEND(t) CONCAT3(ipc, NS, t##_send)
  59. #define NS_CALLBACK(t) CONCAT3(ipc, NS, t##_callback)
  60. #define NS_CODE(t) CONCAT3(IPC, NS_CAP, t)
  61. #define NS_MSG_TYPE(t) struct CONCAT3(shim_ipc, NS, t)
  62. int CONCAT3(add, NS, range) (IDTYPE base, IDTYPE owner,
  63. const char * uri, LEASETYPE lease);
  64. int CONCAT3(del, NS, range) (IDTYPE idx);
  65. int CONCAT3(add, NS, subrange) (IDTYPE idx, IDTYPE owner,
  66. const char * uri, LEASETYPE * lease);
  67. int CONCAT3(del, NS, subrange) (IDTYPE idx);
  68. int CONCAT3(alloc, NS, range) (IDTYPE owner, const char * uri,
  69. IDTYPE * base, LEASETYPE * lease);
  70. struct CONCAT2(NS, range) {
  71. IDTYPE base, size;
  72. IDTYPE owner;
  73. struct shim_qstr uri;
  74. LEASETYPE lease;
  75. struct shim_ipc_port * port;
  76. };
  77. int CONCAT3(get, NS, range) (IDTYPE idx,
  78. struct CONCAT2(NS, range) * range,
  79. struct shim_ipc_info ** pinfo);
  80. enum {
  81. NS_CODE(FINDNS) = CONCAT3(IPC, NS_CAP, BASE),
  82. NS_CODE(TELLNS),
  83. NS_CODE(LEASE),
  84. NS_CODE(OFFER),
  85. NS_CODE(RENEW),
  86. NS_CODE(REVOKE),
  87. NS_CODE(SUBLEASE),
  88. NS_CODE(QUERY),
  89. NS_CODE(QUERYALL),
  90. NS_CODE(ANSWER),
  91. #ifdef NS_KEY
  92. NS_CODE(FINDKEY),
  93. NS_CODE(TELLKEY),
  94. #endif
  95. NS_CODE(TEMPLATE_BOUND),
  96. };
  97. /* FINDNS: find the channel of the namespace leader */
  98. int NS_SEND(findns) (bool block);
  99. int NS_CALLBACK(findns) (IPC_CALLBACK_ARGS);
  100. /* TELLNS: tell the channel of namespace leader */
  101. NS_MSG_TYPE(tellns) {
  102. IDTYPE vmid;
  103. char uri[1];
  104. } __attribute__((packed));
  105. int NS_SEND(tellns) (struct shim_ipc_port * port, IDTYPE dest,
  106. struct shim_ipc_info * leader, unsigned long seq);
  107. int NS_CALLBACK(tellns) (IPC_CALLBACK_ARGS);
  108. /* LEASE: lease a range of name */
  109. NS_MSG_TYPE(lease) {
  110. char uri[1];
  111. } __attribute__((packed));
  112. int NS_SEND(lease) (LEASETYPE * lease);
  113. int NS_CALLBACK(lease) (IPC_CALLBACK_ARGS);
  114. /* OFFER: offer a range of name */
  115. NS_MSG_TYPE(offer) {
  116. IDTYPE base, size;
  117. LEASETYPE lease;
  118. } __attribute__((packed));
  119. int NS_SEND(offer) (struct shim_ipc_port * port, IDTYPE dest, IDTYPE base,
  120. IDTYPE size, LEASETYPE lease, unsigned long seq);
  121. int NS_CALLBACK(offer) (IPC_CALLBACK_ARGS);
  122. /* RENEW: renew lease of a range of name */
  123. NS_MSG_TYPE(renew) {
  124. IDTYPE base, size;
  125. } __attribute__((packed));
  126. int NS_SEND(renew) (IDTYPE base, IDTYPE size);
  127. int NS_CALLBACK(renew) (IPC_CALLBACK_ARGS);
  128. /* REVOKE: revoke lease of a range of name */
  129. NS_MSG_TYPE(revoke) {
  130. IDTYPE base, size;
  131. } __attribute__((packed));
  132. int NS_SEND(revoke) (IDTYPE base, IDTYPE size);
  133. int NS_CALLBACK(revoke) (IPC_CALLBACK_ARGS);
  134. /* SUBLEASE: lease a range of names */
  135. NS_MSG_TYPE(sublease) {
  136. IDTYPE tenant;
  137. IDTYPE idx;
  138. char uri[1];
  139. } __attribute__((packed));
  140. int NS_SEND(sublease) (IDTYPE tenant, IDTYPE idx, const char * uri,
  141. LEASETYPE * lease);
  142. int NS_CALLBACK(sublease) (IPC_CALLBACK_ARGS);
  143. /* QUERY: query the channel of certain name */
  144. NS_MSG_TYPE(query) {
  145. IDTYPE idx;
  146. } __attribute__((packed));
  147. int NS_SEND(query) (IDTYPE idx);
  148. int NS_CALLBACK(query) (IPC_CALLBACK_ARGS);
  149. /* QUERY: query the channel of all names */
  150. int NS_SEND(queryall) (void);
  151. int NS_CALLBACK(queryall) (IPC_CALLBACK_ARGS);
  152. /* ANSWER: answer the channel of certain names */
  153. NS_MSG_TYPE(answer) {
  154. int nanswers;
  155. struct ipc_ns_offered answers[];
  156. } __attribute__((packed));
  157. int NS_SEND(answer) (struct shim_ipc_port * port, IDTYPE dest,
  158. int nanswers, struct ipc_ns_offered * answers,
  159. int nowners, struct ipc_ns_client ** ownerdata,
  160. int * ownerdatasz, unsigned long seq);
  161. int NS_CALLBACK(answer) (IPC_CALLBACK_ARGS);
  162. #ifdef NS_KEY
  163. int CONCAT2(NS, add_key) (NS_KEY * key, IDTYPE id);
  164. int CONCAT2(NS, get_key) (NS_KEY * key, bool delete);
  165. /* FINDKEY */
  166. NS_MSG_TYPE(findkey) {
  167. NS_KEY key;
  168. } __attribute__((packed));
  169. int NS_SEND(findkey) (NS_KEY * key);
  170. int NS_CALLBACK(findkey) (IPC_CALLBACK_ARGS);
  171. /* TELLKEY */
  172. NS_MSG_TYPE(tellkey) {
  173. NS_KEY key;
  174. IDTYPE id;
  175. } __attribute__((packed));
  176. int NS_SEND(tellkey) (struct shim_ipc_port * port, IDTYPE dest, NS_KEY * key,
  177. IDTYPE id, unsigned long seq);
  178. int NS_CALLBACK(tellkey) (IPC_CALLBACK_ARGS);
  179. # undef NS_KEY
  180. #endif
  181. IDTYPE CONCAT2(allocate, NS) (IDTYPE min, IDTYPE max);
  182. void CONCAT2(release, NS) (IDTYPE idx);
  183. int CONCAT3(prepare, NS, leader) (void);
  184. #undef NS_SEND
  185. #undef NS_CALLBACK
  186. #undef NS_CODE
  187. #undef NS_MSG_TYPE
  188. #undef NS
  189. #undef NS_CAP