hyperv.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /*
  2. *
  3. * Copyright (c) 2011, Microsoft Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  16. * Place - Suite 330, Boston, MA 02111-1307 USA.
  17. *
  18. * Authors:
  19. * Haiyang Zhang <haiyangz@microsoft.com>
  20. * Hank Janssen <hjanssen@microsoft.com>
  21. * K. Y. Srinivasan <kys@microsoft.com>
  22. *
  23. */
  24. #ifndef _HYPERV_H
  25. #define _HYPERV_H
  26. #include <linux/uuid.h>
  27. /*
  28. * Framework version for util services.
  29. */
  30. #define UTIL_FW_MINOR 0
  31. #define UTIL_WS2K8_FW_MAJOR 1
  32. #define UTIL_WS2K8_FW_VERSION (UTIL_WS2K8_FW_MAJOR << 16 | UTIL_FW_MINOR)
  33. #define UTIL_FW_MAJOR 3
  34. #define UTIL_FW_VERSION (UTIL_FW_MAJOR << 16 | UTIL_FW_MINOR)
  35. /*
  36. * Implementation of host controlled snapshot of the guest.
  37. */
  38. #define VSS_OP_REGISTER 128
  39. /*
  40. Daemon code with full handshake support.
  41. */
  42. #define VSS_OP_REGISTER1 129
  43. enum hv_vss_op {
  44. VSS_OP_CREATE = 0,
  45. VSS_OP_DELETE,
  46. VSS_OP_HOT_BACKUP,
  47. VSS_OP_GET_DM_INFO,
  48. VSS_OP_BU_COMPLETE,
  49. /*
  50. * Following operations are only supported with IC version >= 5.0
  51. */
  52. VSS_OP_FREEZE, /* Freeze the file systems in the VM */
  53. VSS_OP_THAW, /* Unfreeze the file systems */
  54. VSS_OP_AUTO_RECOVER,
  55. VSS_OP_COUNT /* Number of operations, must be last */
  56. };
  57. /*
  58. * Header for all VSS messages.
  59. */
  60. struct hv_vss_hdr {
  61. __u8 operation;
  62. __u8 reserved[7];
  63. } __attribute__((packed));
  64. /*
  65. * Flag values for the hv_vss_check_feature. Linux supports only
  66. * one value.
  67. */
  68. #define VSS_HBU_NO_AUTO_RECOVERY 0x00000005
  69. struct hv_vss_check_feature {
  70. __u32 flags;
  71. } __attribute__((packed));
  72. struct hv_vss_check_dm_info {
  73. __u32 flags;
  74. } __attribute__((packed));
  75. struct hv_vss_msg {
  76. union {
  77. struct hv_vss_hdr vss_hdr;
  78. int error;
  79. };
  80. union {
  81. struct hv_vss_check_feature vss_cf;
  82. struct hv_vss_check_dm_info dm_info;
  83. };
  84. } __attribute__((packed));
  85. /*
  86. * Implementation of a host to guest copy facility.
  87. */
  88. #define FCOPY_VERSION_0 0
  89. #define FCOPY_VERSION_1 1
  90. #define FCOPY_CURRENT_VERSION FCOPY_VERSION_1
  91. #define W_MAX_PATH 260
  92. enum hv_fcopy_op {
  93. START_FILE_COPY = 0,
  94. WRITE_TO_FILE,
  95. COMPLETE_FCOPY,
  96. CANCEL_FCOPY,
  97. };
  98. struct hv_fcopy_hdr {
  99. __u32 operation;
  100. uuid_le service_id0; /* currently unused */
  101. uuid_le service_id1; /* currently unused */
  102. } __attribute__((packed));
  103. #define OVER_WRITE 0x1
  104. #define CREATE_PATH 0x2
  105. struct hv_start_fcopy {
  106. struct hv_fcopy_hdr hdr;
  107. __u16 file_name[W_MAX_PATH];
  108. __u16 path_name[W_MAX_PATH];
  109. __u32 copy_flags;
  110. __u64 file_size;
  111. } __attribute__((packed));
  112. /*
  113. * The file is chunked into fragments.
  114. */
  115. #define DATA_FRAGMENT (6 * 1024)
  116. struct hv_do_fcopy {
  117. struct hv_fcopy_hdr hdr;
  118. __u32 pad;
  119. __u64 offset;
  120. __u32 size;
  121. __u8 data[DATA_FRAGMENT];
  122. } __attribute__((packed));
  123. /*
  124. * An implementation of HyperV key value pair (KVP) functionality for Linux.
  125. *
  126. *
  127. * Copyright (C) 2010, Novell, Inc.
  128. * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
  129. *
  130. */
  131. /*
  132. * Maximum value size - used for both key names and value data, and includes
  133. * any applicable NULL terminators.
  134. *
  135. * Note: This limit is somewhat arbitrary, but falls easily within what is
  136. * supported for all native guests (back to Win 2000) and what is reasonable
  137. * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
  138. * limited to 255 character key names.
  139. *
  140. * MSDN recommends not storing data values larger than 2048 bytes in the
  141. * registry.
  142. *
  143. * Note: This value is used in defining the KVP exchange message - this value
  144. * cannot be modified without affecting the message size and compatibility.
  145. */
  146. /*
  147. * bytes, including any null terminators
  148. */
  149. #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
  150. /*
  151. * Maximum key size - the registry limit for the length of an entry name
  152. * is 256 characters, including the null terminator
  153. */
  154. #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
  155. /*
  156. * In Linux, we implement the KVP functionality in two components:
  157. * 1) The kernel component which is packaged as part of the hv_utils driver
  158. * is responsible for communicating with the host and responsible for
  159. * implementing the host/guest protocol. 2) A user level daemon that is
  160. * responsible for data gathering.
  161. *
  162. * Host/Guest Protocol: The host iterates over an index and expects the guest
  163. * to assign a key name to the index and also return the value corresponding to
  164. * the key. The host will have atmost one KVP transaction outstanding at any
  165. * given point in time. The host side iteration stops when the guest returns
  166. * an error. Microsoft has specified the following mapping of key names to
  167. * host specified index:
  168. *
  169. * Index Key Name
  170. * 0 FullyQualifiedDomainName
  171. * 1 IntegrationServicesVersion
  172. * 2 NetworkAddressIPv4
  173. * 3 NetworkAddressIPv6
  174. * 4 OSBuildNumber
  175. * 5 OSName
  176. * 6 OSMajorVersion
  177. * 7 OSMinorVersion
  178. * 8 OSVersion
  179. * 9 ProcessorArchitecture
  180. *
  181. * The Windows host expects the Key Name and Key Value to be encoded in utf16.
  182. *
  183. * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
  184. * data gathering functionality in a user mode daemon. The user level daemon
  185. * is also responsible for binding the key name to the index as well. The
  186. * kernel and user-level daemon communicate using a connector channel.
  187. *
  188. * The user mode component first registers with the
  189. * the kernel component. Subsequently, the kernel component requests, data
  190. * for the specified keys. In response to this message the user mode component
  191. * fills in the value corresponding to the specified key. We overload the
  192. * sequence field in the cn_msg header to define our KVP message types.
  193. *
  194. *
  195. * The kernel component simply acts as a conduit for communication between the
  196. * Windows host and the user-level daemon. The kernel component passes up the
  197. * index received from the Host to the user-level daemon. If the index is
  198. * valid (supported), the corresponding key as well as its
  199. * value (both are strings) is returned. If the index is invalid
  200. * (not supported), a NULL key string is returned.
  201. */
  202. /*
  203. * Registry value types.
  204. */
  205. #define REG_SZ 1
  206. #define REG_U32 4
  207. #define REG_U64 8
  208. /*
  209. * As we look at expanding the KVP functionality to include
  210. * IP injection functionality, we need to maintain binary
  211. * compatibility with older daemons.
  212. *
  213. * The KVP opcodes are defined by the host and it was unfortunate
  214. * that I chose to treat the registration operation as part of the
  215. * KVP operations defined by the host.
  216. * Here is the level of compatibility
  217. * (between the user level daemon and the kernel KVP driver) that we
  218. * will implement:
  219. *
  220. * An older daemon will always be supported on a newer driver.
  221. * A given user level daemon will require a minimal version of the
  222. * kernel driver.
  223. * If we cannot handle the version differences, we will fail gracefully
  224. * (this can happen when we have a user level daemon that is more
  225. * advanced than the KVP driver.
  226. *
  227. * We will use values used in this handshake for determining if we have
  228. * workable user level daemon and the kernel driver. We begin by taking the
  229. * registration opcode out of the KVP opcode namespace. We will however,
  230. * maintain compatibility with the existing user-level daemon code.
  231. */
  232. /*
  233. * Daemon code not supporting IP injection (legacy daemon).
  234. */
  235. #define KVP_OP_REGISTER 4
  236. /*
  237. * Daemon code supporting IP injection.
  238. * The KVP opcode field is used to communicate the
  239. * registration information; so define a namespace that
  240. * will be distinct from the host defined KVP opcode.
  241. */
  242. #define KVP_OP_REGISTER1 100
  243. enum hv_kvp_exchg_op {
  244. KVP_OP_GET = 0,
  245. KVP_OP_SET,
  246. KVP_OP_DELETE,
  247. KVP_OP_ENUMERATE,
  248. KVP_OP_GET_IP_INFO,
  249. KVP_OP_SET_IP_INFO,
  250. KVP_OP_COUNT /* Number of operations, must be last. */
  251. };
  252. enum hv_kvp_exchg_pool {
  253. KVP_POOL_EXTERNAL = 0,
  254. KVP_POOL_GUEST,
  255. KVP_POOL_AUTO,
  256. KVP_POOL_AUTO_EXTERNAL,
  257. KVP_POOL_AUTO_INTERNAL,
  258. KVP_POOL_COUNT /* Number of pools, must be last. */
  259. };
  260. /*
  261. * Some Hyper-V status codes.
  262. */
  263. #define HV_S_OK 0x00000000
  264. #define HV_E_FAIL 0x80004005
  265. #define HV_S_CONT 0x80070103
  266. #define HV_ERROR_NOT_SUPPORTED 0x80070032
  267. #define HV_ERROR_MACHINE_LOCKED 0x800704F7
  268. #define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F
  269. #define HV_INVALIDARG 0x80070057
  270. #define HV_GUID_NOTFOUND 0x80041002
  271. #define HV_ERROR_ALREADY_EXISTS 0x80070050
  272. #define ADDR_FAMILY_NONE 0x00
  273. #define ADDR_FAMILY_IPV4 0x01
  274. #define ADDR_FAMILY_IPV6 0x02
  275. #define MAX_ADAPTER_ID_SIZE 128
  276. #define MAX_IP_ADDR_SIZE 1024
  277. #define MAX_GATEWAY_SIZE 512
  278. struct hv_kvp_ipaddr_value {
  279. __u16 adapter_id[MAX_ADAPTER_ID_SIZE];
  280. __u8 addr_family;
  281. __u8 dhcp_enabled;
  282. __u16 ip_addr[MAX_IP_ADDR_SIZE];
  283. __u16 sub_net[MAX_IP_ADDR_SIZE];
  284. __u16 gate_way[MAX_GATEWAY_SIZE];
  285. __u16 dns_addr[MAX_IP_ADDR_SIZE];
  286. } __attribute__((packed));
  287. struct hv_kvp_hdr {
  288. __u8 operation;
  289. __u8 pool;
  290. __u16 pad;
  291. } __attribute__((packed));
  292. struct hv_kvp_exchg_msg_value {
  293. __u32 value_type;
  294. __u32 key_size;
  295. __u32 value_size;
  296. __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  297. union {
  298. __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
  299. __u32 value_u32;
  300. __u64 value_u64;
  301. };
  302. } __attribute__((packed));
  303. struct hv_kvp_msg_enumerate {
  304. __u32 index;
  305. struct hv_kvp_exchg_msg_value data;
  306. } __attribute__((packed));
  307. struct hv_kvp_msg_get {
  308. struct hv_kvp_exchg_msg_value data;
  309. };
  310. struct hv_kvp_msg_set {
  311. struct hv_kvp_exchg_msg_value data;
  312. };
  313. struct hv_kvp_msg_delete {
  314. __u32 key_size;
  315. __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  316. };
  317. struct hv_kvp_register {
  318. __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  319. };
  320. struct hv_kvp_msg {
  321. union {
  322. struct hv_kvp_hdr kvp_hdr;
  323. int error;
  324. };
  325. union {
  326. struct hv_kvp_msg_get kvp_get;
  327. struct hv_kvp_msg_set kvp_set;
  328. struct hv_kvp_msg_delete kvp_delete;
  329. struct hv_kvp_msg_enumerate kvp_enum_data;
  330. struct hv_kvp_ipaddr_value kvp_ip_val;
  331. struct hv_kvp_register kvp_register;
  332. } body;
  333. } __attribute__((packed));
  334. struct hv_kvp_ip_msg {
  335. __u8 operation;
  336. __u8 pool;
  337. struct hv_kvp_ipaddr_value kvp_ip_val;
  338. } __attribute__((packed));
  339. #endif /* _HYPERV_H */