shim_ipc_ns.h 6.8 KB

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