📄 xen_vm.c
字号:
/* * Copyright (c) 2006-2007, XenSource Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <stddef.h>#include <stdlib.h>#include "xen_internal.h"#include "xen_on_crash_behaviour_internal.h"#include "xen_on_normal_exit_internal.h"#include "xen_vm_power_state_internal.h"#include <xen/api/xen_common.h>#include <xen/api/xen_console.h>#include <xen/api/xen_crashdump.h>#include <xen/api/xen_host.h>#include <xen/api/xen_string_string_map.h>#include <xen/api/xen_vbd.h>#include <xen/api/xen_vdi.h>#include <xen/api/xen_vif.h>#include <xen/api/xen_vm.h>#include <xen/api/xen_vm_guest_metrics.h>#include <xen/api/xen_vm_metrics.h>#include <xen/api/xen_vtpm.h>XEN_FREE(xen_vm)XEN_SET_ALLOC_FREE(xen_vm)XEN_ALLOC(xen_vm_record)XEN_SET_ALLOC_FREE(xen_vm_record)XEN_ALLOC(xen_vm_record_opt)XEN_RECORD_OPT_FREE(xen_vm)XEN_SET_ALLOC_FREE(xen_vm_record_opt)static const struct_member xen_vm_record_struct_members[] = { { .key = "uuid", .type = &abstract_type_string, .offset = offsetof(xen_vm_record, uuid) }, { .key = "power_state", .type = &xen_vm_power_state_abstract_type_, .offset = offsetof(xen_vm_record, power_state) }, { .key = "name_label", .type = &abstract_type_string, .offset = offsetof(xen_vm_record, name_label) }, { .key = "name_description", .type = &abstract_type_string, .offset = offsetof(xen_vm_record, name_description) }, { .key = "user_version", .type = &abstract_type_int, .offset = offsetof(xen_vm_record, user_version) }, { .key = "is_a_template", .type = &abstract_type_bool, .offset = offsetof(xen_vm_record, is_a_template) }, { .key = "auto_power_on", .type = &abstract_type_bool, .offset = offsetof(xen_vm_record, auto_power_on) }, { .key = "suspend_VDI", .type = &abstract_type_ref, .offset = offsetof(xen_vm_record, suspend_vdi) }, { .key = "resident_on", .type = &abstract_type_ref, .offset = offsetof(xen_vm_record, resident_on) }, { .key = "memory_static_max", .type = &abstract_type_int, .offset = offsetof(xen_vm_record, memory_static_max) }, { .key = "memory_dynamic_max", .type = &abstract_type_int, .offset = offsetof(xen_vm_record, memory_dynamic_max) }, { .key = "memory_dynamic_min", .type = &abstract_type_int, .offset = offsetof(xen_vm_record, memory_dynamic_min) }, { .key = "memory_static_min", .type = &abstract_type_int, .offset = offsetof(xen_vm_record, memory_static_min) }, { .key = "VCPUs_params", .type = &abstract_type_string_string_map, .offset = offsetof(xen_vm_record, vcpus_params) }, { .key = "VCPUs_max", .type = &abstract_type_int, .offset = offsetof(xen_vm_record, vcpus_max) }, { .key = "VCPUs_at_startup", .type = &abstract_type_int, .offset = offsetof(xen_vm_record, vcpus_at_startup) }, { .key = "actions_after_shutdown", .type = &xen_on_normal_exit_abstract_type_, .offset = offsetof(xen_vm_record, actions_after_shutdown) }, { .key = "actions_after_reboot", .type = &xen_on_normal_exit_abstract_type_, .offset = offsetof(xen_vm_record, actions_after_reboot) }, { .key = "actions_after_crash", .type = &xen_on_crash_behaviour_abstract_type_, .offset = offsetof(xen_vm_record, actions_after_crash) }, { .key = "consoles", .type = &abstract_type_ref_set, .offset = offsetof(xen_vm_record, consoles) }, { .key = "VIFs", .type = &abstract_type_ref_set, .offset = offsetof(xen_vm_record, vifs) }, { .key = "VBDs", .type = &abstract_type_ref_set, .offset = offsetof(xen_vm_record, vbds) }, { .key = "crash_dumps", .type = &abstract_type_ref_set, .offset = offsetof(xen_vm_record, crash_dumps) }, { .key = "VTPMs", .type = &abstract_type_ref_set, .offset = offsetof(xen_vm_record, vtpms) }, { .key = "PV_bootloader", .type = &abstract_type_string, .offset = offsetof(xen_vm_record, pv_bootloader) }, { .key = "PV_kernel", .type = &abstract_type_string, .offset = offsetof(xen_vm_record, pv_kernel) }, { .key = "PV_ramdisk", .type = &abstract_type_string, .offset = offsetof(xen_vm_record, pv_ramdisk) }, { .key = "PV_args", .type = &abstract_type_string, .offset = offsetof(xen_vm_record, pv_args) }, { .key = "PV_bootloader_args", .type = &abstract_type_string, .offset = offsetof(xen_vm_record, pv_bootloader_args) }, { .key = "HVM_boot_policy", .type = &abstract_type_string, .offset = offsetof(xen_vm_record, hvm_boot_policy) }, { .key = "HVM_boot_params", .type = &abstract_type_string_string_map, .offset = offsetof(xen_vm_record, hvm_boot_params) }, { .key = "platform", .type = &abstract_type_string_string_map, .offset = offsetof(xen_vm_record, platform) }, { .key = "PCI_bus", .type = &abstract_type_string, .offset = offsetof(xen_vm_record, pci_bus) }, { .key = "other_config", .type = &abstract_type_string_string_map, .offset = offsetof(xen_vm_record, other_config) }, { .key = "domid", .type = &abstract_type_int, .offset = offsetof(xen_vm_record, domid) }, { .key = "is_control_domain", .type = &abstract_type_bool, .offset = offsetof(xen_vm_record, is_control_domain) }, { .key = "metrics", .type = &abstract_type_ref, .offset = offsetof(xen_vm_record, metrics) }, { .key = "guest_metrics", .type = &abstract_type_ref, .offset = offsetof(xen_vm_record, guest_metrics) }, { .key = "security_label", .type = &abstract_type_string, .offset = offsetof(xen_vm_record, security_label) } };const abstract_type xen_vm_record_abstract_type_ = { .typename = STRUCT, .struct_size = sizeof(xen_vm_record), .member_count = sizeof(xen_vm_record_struct_members) / sizeof(struct_member), .members = xen_vm_record_struct_members };voidxen_vm_record_free(xen_vm_record *record){ if (record == NULL) { return; } free(record->handle); free(record->uuid); free(record->name_label); free(record->name_description); xen_vdi_record_opt_free(record->suspend_vdi); xen_host_record_opt_free(record->resident_on); xen_string_string_map_free(record->vcpus_params); xen_console_record_opt_set_free(record->consoles); xen_vif_record_opt_set_free(record->vifs); xen_vbd_record_opt_set_free(record->vbds); xen_crashdump_record_opt_set_free(record->crash_dumps); xen_vtpm_record_opt_set_free(record->vtpms); free(record->pv_bootloader); free(record->pv_kernel); free(record->pv_ramdisk); free(record->pv_args); free(record->pv_bootloader_args); free(record->hvm_boot_policy); xen_string_string_map_free(record->hvm_boot_params); xen_string_string_map_free(record->platform); free(record->pci_bus); xen_string_string_map_free(record->other_config); xen_vm_metrics_record_opt_free(record->metrics); xen_vm_guest_metrics_record_opt_free(record->guest_metrics); free(record->security_label); free(record);}boolxen_vm_get_record(xen_session *session, xen_vm_record **result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = xen_vm_record_abstract_type_; *result = NULL; XEN_CALL_("VM.get_record"); if (session->ok) { (*result)->handle = xen_strdup_((*result)->uuid); } return session->ok;}boolxen_vm_get_by_uuid(xen_session *session, xen_vm *result, char *uuid){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = uuid } }; abstract_type result_type = abstract_type_string; *result = NULL; XEN_CALL_("VM.get_by_uuid"); return session->ok;}boolxen_vm_create(xen_session *session, xen_vm *result, xen_vm_record *record){ abstract_value param_values[] = { { .type = &xen_vm_record_abstract_type_, .u.struct_val = record } }; abstract_type result_type = abstract_type_string; *result = NULL; XEN_CALL_("VM.create"); return session->ok;}boolxen_vm_destroy(xen_session *session, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; xen_call_(session, "VM.destroy", param_values, 1, NULL, NULL); return session->ok;}boolxen_vm_get_by_name_label(xen_session *session, struct xen_vm_set **result, char *label){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = label } }; abstract_type result_type = abstract_type_string_set; *result = NULL; XEN_CALL_("VM.get_by_name_label"); return session->ok;}boolxen_vm_get_power_state(xen_session *session, enum xen_vm_power_state *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = xen_vm_power_state_abstract_type_; XEN_CALL_("VM.get_power_state"); return session->ok;}boolxen_vm_get_name_label(xen_session *session, char **result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_string; *result = NULL; XEN_CALL_("VM.get_name_label"); return session->ok;}boolxen_vm_get_name_description(xen_session *session, char **result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_string; *result = NULL; XEN_CALL_("VM.get_name_description"); return session->ok;}boolxen_vm_get_user_version(xen_session *session, int64_t *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_int; XEN_CALL_("VM.get_user_version"); return session->ok;}boolxen_vm_get_is_a_template(xen_session *session, bool *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_bool; XEN_CALL_("VM.get_is_a_template"); return session->ok;}boolxen_vm_get_auto_power_on(xen_session *session, bool *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_bool; XEN_CALL_("VM.get_auto_power_on"); return session->ok;}boolxen_vm_get_suspend_vdi(xen_session *session, xen_vdi *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_string; *result = NULL; XEN_CALL_("VM.get_suspend_VDI"); return session->ok;}boolxen_vm_get_resident_on(xen_session *session, xen_host *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_string; *result = NULL; XEN_CALL_("VM.get_resident_on"); return session->ok;}boolxen_vm_get_memory_static_max(xen_session *session, int64_t *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_int; XEN_CALL_("VM.get_memory_static_max"); return session->ok;}boolxen_vm_get_memory_dynamic_max(xen_session *session, int64_t *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_int; XEN_CALL_("VM.get_memory_dynamic_max"); return session->ok;}boolxen_vm_get_memory_dynamic_min(xen_session *session, int64_t *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_int; XEN_CALL_("VM.get_memory_dynamic_min"); return session->ok;}boolxen_vm_get_memory_static_min(xen_session *session, int64_t *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_int; XEN_CALL_("VM.get_memory_static_min"); return session->ok;}boolxen_vm_get_vcpus_params(xen_session *session, xen_string_string_map **result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_string_string_map; *result = NULL; XEN_CALL_("VM.get_VCPUs_params"); return session->ok;}boolxen_vm_get_vcpus_max(xen_session *session, int64_t *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_int; XEN_CALL_("VM.get_VCPUs_max"); return session->ok;}boolxen_vm_get_vcpus_at_startup(xen_session *session, int64_t *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = abstract_type_int; XEN_CALL_("VM.get_VCPUs_at_startup"); return session->ok;}boolxen_vm_get_actions_after_shutdown(xen_session *session, enum xen_on_normal_exit *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = xen_on_normal_exit_abstract_type_; XEN_CALL_("VM.get_actions_after_shutdown"); return session->ok;}boolxen_vm_get_actions_after_reboot(xen_session *session, enum xen_on_normal_exit *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = xen_on_normal_exit_abstract_type_; XEN_CALL_("VM.get_actions_after_reboot"); return session->ok;}boolxen_vm_get_actions_after_crash(xen_session *session, enum xen_on_crash_behaviour *result, xen_vm vm){ abstract_value param_values[] = { { .type = &abstract_type_string, .u.string_val = vm } }; abstract_type result_type = xen_on_crash_behaviour_abstract_type_; XEN_CALL_("VM.get_actions_after_crash"); return session->ok;}boolxen_vm_get_consoles(xen_session *session, struct xen_console_set **result, xen_vm vm)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -