shim_ipc_ns.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. /* SUBLEASE */ &ipc_##ns##_sublease_callback, \
  29. /* QUERY */ &ipc_##ns##_query_callback, \
  30. /* QUERYALL */ &ipc_##ns##_queryall_callback, \
  31. /* ANSWER */ &ipc_##ns##_answer_callback,
  32. #define IPC_NS_KEY_CALLBACKS(ns) \
  33. /* FINDKEY */ &ipc_##ns##_findkey_callback, \
  34. /* TELLKEY */ &ipc_##ns##_tellkey_callback,
  35. #define NS_PORT_CONSTS(n) \
  36. n##CLT, \
  37. n##LDR, \
  38. n##CON, \
  39. n##OWN,
  40. #define NS_PORT_TYPES(n) \
  41. IPC_PORT_##n##CLT = 1<<n##CLT, \
  42. IPC_PORT_##n##LDR = 1<<n##LDR, \
  43. IPC_PORT_##n##CON = 1<<n##CON, \
  44. IPC_PORT_##n##OWN = 1<<n##OWN,
  45. struct ipc_ns_offered {
  46. IDTYPE base, size;
  47. LEASETYPE lease;
  48. unsigned int owner_offset;
  49. } __attribute__((packed));
  50. struct ipc_ns_client {
  51. IDTYPE vmid;
  52. char uri[1];
  53. } __attribute__((packed));
  54. #endif /* __SHIM_IPC_NS_H__ */
  55. #define NS_SEND(t) CONCAT3(ipc, NS, t##_send)
  56. #define NS_CALLBACK(t) CONCAT3(ipc, NS, t##_callback)
  57. #define NS_CODE(t) CONCAT3(IPC, NS_CAP, t)
  58. #define NS_MSG_TYPE(t) struct CONCAT3(shim_ipc, NS, t)
  59. int CONCAT3(add, NS, range) (IDTYPE base, IDTYPE owner,
  60. const char * uri, LEASETYPE lease);
  61. int CONCAT3(del, NS, range) (IDTYPE idx);
  62. int CONCAT3(add, NS, subrange) (IDTYPE idx, IDTYPE owner,
  63. const char * uri, LEASETYPE * lease);
  64. int CONCAT3(del, NS, subrange) (IDTYPE idx);
  65. int CONCAT3(alloc, NS, range) (IDTYPE owner, const char * uri,
  66. IDTYPE * base, LEASETYPE * lease);
  67. struct CONCAT2(NS, range) {
  68. IDTYPE base, size;
  69. IDTYPE owner;
  70. struct shim_qstr uri;
  71. LEASETYPE lease;
  72. struct shim_ipc_port * port;
  73. };
  74. int CONCAT3(get, NS, range) (IDTYPE idx,
  75. struct CONCAT2(NS, range) * range,
  76. struct shim_ipc_info ** pinfo);
  77. enum {
  78. NS_CODE(FINDNS) = CONCAT3(IPC, NS_CAP, BASE),
  79. NS_CODE(TELLNS),
  80. NS_CODE(LEASE),
  81. NS_CODE(OFFER),
  82. NS_CODE(RENEW),
  83. NS_CODE(SUBLEASE),
  84. NS_CODE(QUERY),
  85. NS_CODE(QUERYALL),
  86. NS_CODE(ANSWER),
  87. #ifdef NS_KEY
  88. NS_CODE(FINDKEY),
  89. NS_CODE(TELLKEY),
  90. #endif
  91. NS_CODE(TEMPLATE_BOUND),
  92. };
  93. /* FINDNS: find the channel of the namespace leader */
  94. int NS_SEND(findns) (bool block);
  95. int NS_CALLBACK(findns) (IPC_CALLBACK_ARGS);
  96. /* TELLNS: tell the channel of namespace leader */
  97. NS_MSG_TYPE(tellns) {
  98. IDTYPE vmid;
  99. char uri[1];
  100. } __attribute__((packed));
  101. int NS_SEND(tellns) (struct shim_ipc_port * port, IDTYPE dest,
  102. struct shim_ipc_info * leader, unsigned long seq);
  103. int NS_CALLBACK(tellns) (IPC_CALLBACK_ARGS);
  104. /* LEASE: lease a range of name */
  105. NS_MSG_TYPE(lease) {
  106. char uri[1];
  107. } __attribute__((packed));
  108. int NS_SEND(lease) (LEASETYPE * lease);
  109. int NS_CALLBACK(lease) (IPC_CALLBACK_ARGS);
  110. /* OFFER: offer a range of name */
  111. NS_MSG_TYPE(offer) {
  112. IDTYPE base, size;
  113. LEASETYPE lease;
  114. } __attribute__((packed));
  115. int NS_SEND(offer) (struct shim_ipc_port * port, IDTYPE dest, IDTYPE base,
  116. IDTYPE size, LEASETYPE lease, unsigned long seq);
  117. int NS_CALLBACK(offer) (IPC_CALLBACK_ARGS);
  118. /* RENEW: renew lease of a range of name */
  119. NS_MSG_TYPE(renew) {
  120. IDTYPE base, size;
  121. } __attribute__((packed));
  122. int NS_SEND(renew) (IDTYPE base, IDTYPE size);
  123. int NS_CALLBACK(renew) (IPC_CALLBACK_ARGS);
  124. /* SUBLEASE: lease a range of names */
  125. NS_MSG_TYPE(sublease) {
  126. IDTYPE tenant;
  127. IDTYPE idx;
  128. char uri[1];
  129. } __attribute__((packed));
  130. int NS_SEND(sublease) (IDTYPE tenant, IDTYPE idx, const char * uri,
  131. LEASETYPE * lease);
  132. int NS_CALLBACK(sublease) (IPC_CALLBACK_ARGS);
  133. /* QUERY: query the channel of certain name */
  134. NS_MSG_TYPE(query) {
  135. IDTYPE idx;
  136. } __attribute__((packed));
  137. int NS_SEND(query) (IDTYPE idx);
  138. int NS_CALLBACK(query) (IPC_CALLBACK_ARGS);
  139. /* QUERY: query the channel of all names */
  140. int NS_SEND(queryall) (void);
  141. int NS_CALLBACK(queryall) (IPC_CALLBACK_ARGS);
  142. /* ANSWER: answer the channel of certain names */
  143. NS_MSG_TYPE(answer) {
  144. int nanswers;
  145. struct ipc_ns_offered answers[];
  146. } __attribute__((packed));
  147. int NS_SEND(answer) (struct shim_ipc_port * port, IDTYPE dest,
  148. int nanswers, struct ipc_ns_offered * answers,
  149. int nowners, struct ipc_ns_client ** ownerdata,
  150. int * ownerdatasz, unsigned long seq);
  151. int NS_CALLBACK(answer) (IPC_CALLBACK_ARGS);
  152. #ifdef NS_KEY
  153. int CONCAT2(NS, add_key) (NS_KEY * key, IDTYPE id);
  154. int CONCAT2(NS, get_key) (NS_KEY * key, bool delete);
  155. /* FINDKEY */
  156. NS_MSG_TYPE(findkey) {
  157. NS_KEY key;
  158. } __attribute__((packed));
  159. int NS_SEND(findkey) (NS_KEY * key);
  160. int NS_CALLBACK(findkey) (IPC_CALLBACK_ARGS);
  161. /* TELLKEY */
  162. NS_MSG_TYPE(tellkey) {
  163. NS_KEY key;
  164. IDTYPE id;
  165. } __attribute__((packed));
  166. int NS_SEND(tellkey) (struct shim_ipc_port * port, IDTYPE dest, NS_KEY * key,
  167. IDTYPE id, unsigned long seq);
  168. int NS_CALLBACK(tellkey) (IPC_CALLBACK_ARGS);
  169. # undef NS_KEY
  170. #endif
  171. IDTYPE CONCAT2(allocate, NS) (IDTYPE min, IDTYPE max);
  172. void CONCAT2(release, NS) (IDTYPE idx);
  173. int CONCAT3(prepare, NS, leader) (void);
  174. #undef NS_SEND
  175. #undef NS_CALLBACK
  176. #undef NS_CODE
  177. #undef NS_MSG_TYPE
  178. #undef NS
  179. #undef NS_CAP